我想计算上个月在每个诊所看过的患者人数,所以这是我使用的要求:
SELECT dispensaire.IdDisp,
COUNT(SELECT consultation.NumDossier
FROM consultation
WHERE consultation.Date IN (SELECT consultation.Date
FROM consultation
WHERE consultation.Date BETWEEN (CURRENT_DATE( ) - INTERVAL 1 MONTH) AND CURRENT_DATE( )))
FROM dispensaire, medecin, consultation
WHERE dispensaire.IdDisp=medecin.IdDisp
AND medecin.IdDisp.consultation.IdDisp
GROUP BY dispensaire.IdDisp
我找不到我的请求出了什么问题!谢谢
最佳答案
您在以下行中有错别字-两列之间缺少等号:
AND medecin.IdDisp.consultation.IdDisp
该行应为:
AND medecin.IdDisp = consultation.IdDisp
我可能建议将查询重写为类似这样的形式,它在表上使用JOIN语法而不是
WHERE
子句中的联接:SELECT d.IdDisp,
COUNT(c.NumDossier)
FROM dispensaire d
INNER JOIN medecin m
ON d.IdDisp = m.IdDisp
INNER JOIN consultation c
ON m.IdDisp = c.IdDisp
WHERE c.Date BETWEEN (CURRENT_DATE( ) - INTERVAL 1 MONTH) AND CURRENT_DATE( ))
GROUP BY d.IdDisp
关于mysql - MySQL请求COUNT个问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20910524/