我被告知找出条件ID = MC8的患者数量最多的职业 我dk怎么做最大的部分..... 现在我的代码
SELECT occupation
FROM Patient
WHERE EXISTS
(SELECT PatientID FROM PatientMedcon
Where conditionID=’MC8’)
GROUP BY occupation
HAVNG count(occupation) = (Select max(occupation)
From Patient
答案 0 :(得分:0)
您应该使用常规联接来处理这些类型的查询,然后添加其他因素。以下是每种职业患者的病情计数:
SELECT occupation, COUNT(*)
FROM Patient p JOIN
PatentMedcon pm
ON p.PatientId = pm.PatientId and
pm.conditionId = 'MC8'
GROUP BY occupation
ORDER BY COUNT(*) DESC;
如果你想要顶行,那取决于数据库。最后可能是select top 1
,limit 1
,最后是fetch first 1 rows only
,甚至可能是其他内容。