2017-10-04 86 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

它非常有用。谢啦 –