2013-02-20 67 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