1
我想每個月來算耐心,我需要看到結果每個月數哪怕是0計數患者每月
,我運行應該給13
上月查詢其他月份的號碼爲3
和0
。但正在發生的事情是多少13
劃分並分配到所有12個月類似如下:
這裏是查詢:
SELECT
count(patients) as patients, month
FROM
(
SELECT
count(app_id) as patients,
month(date_app) as month
FROM
dentist.appointment
WHERE id_logged=1 AND year(date_app)='2016'
GROUP BY month(date_app)
UNION SELECT 0,1
UNION SELECT 0,2
UNION SELECT 0,3
UNION SELECT 0,4
UNION SELECT 0,5
UNION SELECT 0,6
UNION SELECT 0,7
UNION SELECT 0,8
UNION SELECT 0,9
UNION SELECT 0,10
UNION SELECT 0,11
UNION SELECT 0,12
) tmp
GROUP BY month
沒了,仍然只得到'病人:13 ||月:3' – androidnation
@androidnation愚蠢的錯誤。我應該在'ON'中放置'WHERE'子句的謂詞。檢查我所做的編輯。 –
完成。它正在工作。你能爲我解釋一下查詢嗎? – androidnation