首先,我的 SQL 知识有点生疏。我正在尝试生成每个患者在一段时间内经历的评论报告。审查是作为医生轮次的一部分进行的。以下是具有相关列的相应表格:
Patients: (id, name)
Rounds: (id, patient_id, date)
Reviews: (id, round_id, review)
报告应如下所示:
Patient | Reviews
_________________________
Patient 1 | 2
_________________________
Patient 2 | 1
_________________________
Patient 3 | 0
_________________________
我尝试了以下 SQL 语句:
SELECT
p.name as patient,
COUNT(r.round_id) as reviews
FROM
patients as p
JOIN rounds as ro ON p.id = ro.patient_id
JOIN reviews as r ON ro.id = r.round_id
WHERE
r.review_date between '2012-02-01' AND '2012-02-29'
GROUP BY
p.name
但是,上面的查询只返回评论数大于 1 的行。即使计数为 0,我也希望它返回。