2013-02-20 42 views
-1

heres a table of diagnosis i want to query the diagnosis and count the number of patient_ID diagnosed by it. so it has to be one diagnoes with numbers of patient BUT the next picture comes in the complaint table part where the query has to be with a certain month only如何从一个外键

enter image description here

继承人诊断的表我要查询的诊断和统计由它诊断patient_ID的数量挂钩两个不同的表查询。所以它必须是一个患者数量的诊断但是下一张图片出现在投诉表部分,其中查询必须与某个月仅有

+0

你到目前为止尝试过什么? – 2013-02-20 12:23:15

+1

这些日子里没有人阅读教程/手册吗? – fancyPants 2013-02-20 12:23:32

+0

你需要什么样的输出以及表格结构和哪些DBMS? – CloudyMarble 2013-02-20 12:23:43

回答

1

我猜您需要将两个表格连接成两列: complaint_IDpatient_ID

SELECT a.diagnosis, COUNT(a.patient_ID) totalAmidtted 
FROM diagnosis a 
     LEFT JOIN admitted b 
      ON a.complaint_ID = b.complaint_ID AND 
       a.patient_ID = b.patient_ID 
WHERE b.date_time BETWEEN 'fromDate' AND 'toDate' 
GROUP BY a.diagnosis 

为了进一步获得更多的知识有关加入,请访问以下链接:

题外话:你是菲律宾人吧?特别是bisaya :D

+0

哈哈哈。 g unsa nimo pagkahibaw? – 2013-02-20 15:14:31

+0

@Belmark在SO中说母语是严格禁止的。 ':D'通过查看您的示例数据。 – 2013-02-20 15:20:49

+1

哈哈..对不起,我刚刚在这里。是啊,傻我。哈哈哈。但感谢兄弟它解决了我的问题,我们有同样的查询,我缺少的是patient_ID和complaint_ID – 2013-02-20 15:26:23