2017-10-04 45 views
-1

DATAS我有這樣關於顯示通過子查詢

http://sqlfiddle.com/#!3/690e8

  1. 架構如何顯示doctorid,doctorname,doctorphone和doctorbirthyear(從doctorbirthdate的一年),那裏的醫生從來沒有做過的檢查。

  2. 如何顯示該藥物在一年中的第12個月出售的藥物名稱,藥物類型名稱和藥物價格。

  3. 我該如何顯示medicid,medicinename和medicineprice(含USD)藥品不是由doctorid ='dc001'出售。

  4. 如何顯示病人,患者姓名和患者年限(從患者年份開始),患者由醫生服務的年齡小於患者。

我叔叔問我,即使解決了這個,雖然我是一個數字藝術系學生(這是複雜的),說實話,我關於MySQL幾乎沒有想法,只是基本的東西。請懇請您幫我解決這些問題。我會很感激!

+0

分享您爲解決上述問題而採取的一些代碼/查詢工作,它不僅僅是發佈問題 – akhilsk

回答

0

1日問題

SELECT DoctorID, DoctorName, DoctorPhone, YEAR(DoctorBirthDate) as 'DoctorBirthYear' 
FROM MsDoctor 
WHERE DoctorID NOT IN (SELECT DoctorID FROM TransactionHeader); 

第二個問題

SELECT MsMedicine.MedicineName, CONCAT(MsMedicine.MedicinePrice,' USD'), MsMedicineType.MedicineTypeName 
FROM MsMedicine 
INNER JOIN MsMedicineType ON MsMedicineType.MedicineTypeID = MsMedicine.MedicineTypeID 
WHERE MedicineID IN (
    SELECT MedicineID FROM TransactionDetail 
    WHERE TransactionID IN (
     SELECT TransactionID from TransactionHeader 
     WHERE MONTH(TransactionDate) = 12 
    ) 
) 
0

1-如何顯示那裏的醫生從來沒有做過檢查doctorid,doctorname,doctorphone和doctorbirthyear(從doctorbirthdate的一年)。

select doctorid, doctorname, doctorphone , year(DoctorBirthDate) as doctorbirthyear 
from msdoctor 
where doctorid not in (select doctorid from transactionheader) ; 

2-如何顯示該藥物在一年中的第12個月出售的藥物名稱,藥物類型名稱和藥物價格。

select medicinename, medicinetypename, medicineprice 
from MsMedicineType mt, MsMedicine m , TransactionDetail td, TransactionHeader th 
where mt.MedicineTypeID=m.MedicineTypeID and m.MedicineID=td.MedicineID and td.TransactionID=th.TransactionID and month(th.TransactionDate) = 12; 

3-如何顯示medicid,medicinename和medicineprice(含USD)藥物不是由doctorid ='dc001'銷售的。

select medicinename, medicinetypename, concat(medicineprice,'$') as medicineprice 
from MsMedicineType mt, MsMedicine m , TransactionDetail td, TransactionHeader th 
where mt.MedicineTypeID=m.MedicineTypeID and m.MedicineID=td.MedicineID and td.TransactionID=th.TransactionID and th.DoctorID!='dc001'; 

4-如何顯示patientid,patientname和patientbirthyear(從patientbirthdate的一年)該病人被醫生比病人年輕化服務。

select p.patientid, p.patientname, year(PatientBirthDate) as patientbirthyear 
from TransactionHeader th , msdoctor m, mspatient p 
where th.DoctorID=m.DoctorID and th.PatientID=p.PatientID and PatientBirthDate>DoctorBirthDate; 

希望這會有所幫助。

+0

它非常有用。謝啦 –