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