SQL查询:
解决方案:我已经完成了这些问题的这些答案,但不确定是否可以。如果有任何错误或需要更正,请帮助我。
1。)
select SSN, Name
from patient
where age < (
select avg(age)
from Patient
);
2。)
select patient.name, max(patient.age), patient.DName
from Patient
join Doctor
where patient.primary_DoctorID = Doctor.DoctorID;
3。)
SELECT Patient.Name, Patient.age
from Patient
where patient.age < '50' and Patient.Primary_DoctorID = (
SELECT Prescription.DoctorID
from Prescription
where Prescription.P_ID = (
select Prescription_Medicine.P_ID
FROM Prescription_Medicine
where Prescription_Medicine.Tradename = 'Vitamin' )
);
第三季度回报
子查询返回多个行
SELECT dname
FROM doctor
IN speciality = 'Heart' AND experience = (
SELECT MAX(doctor.experience)
FROM doctor
GROUP BY speciality;
);
答案 0 :(得分:0)
将您的第三个查询更新为-
SELECT Patient.Name, Patient.age
from Patient
where patient.age < '50'
and EXISTS (
SELECT Prescription.DoctorID
from Prescription
where Patient.Primary_DoctorID = Prescription.DoctorID
and Prescription.P_ID = (
select Prescription_Medicine.P_ID
FROM Prescription_Medicine
where Prescription_Medicine.Tradename = 'Vitamin' )
);
并将您的第四个查询更新为-
SELECT dname
FROM doctor d
JOIN (SELECT speciality, MAX(doctor.experience)
FROM doctor
GROUP BY speciality) d1 on d.speciality = d1.speciality
WHERE speciality = 'Heart'
答案 1 :(得分:-1)
--使用 MS-SQL SERVER 进行第四次查询
--你也可以用窗口函数解决第四个
- 询问。
--使用CTE(通用表表达式)
具有 CTE 作为 ( 选择 D.DNAME, DENSE_RANK() OVER (PARTITION BY D.DNAME ORDER BY D. 经验描述)作为 RNK 来自医生 哪里专业 = '心' )
从 CTE 中选择 DNAME 哪里 RNK = 1