我正在努力使这个查询工作,但我无法理解我做错了什么。我看到了同样问题的其他问题,但我还是不明白。
SELECT DoctorsVisits.VisitDate,
(SELECT COUNT(1) AS Total
FROM DoctorsVisits
WHERE (DoctorsVisits.PeriodOfVisitId=2)
GROUP BY DoctorsVisits.VisitDate) AS Manhas
FROM DoctorsVisits;
答案 0 :(得分:1)
你确定你不是只想要一个没有子查询的普通组吗?
SELECT DoctorsVisits.VisitDate, count(*) as Manhas
FROM DoctorsVisits
group by DoctorsVisits.VisitDate
或者也许:
SELECT DoctorsVisits.VisitDate,
sum(case when DoctorsVisits.PeriodOfVisitId=2 then 1 else 0 end) as Manhas
FROM DoctorsVisits
group by DoctorsVisits.VisitDate
答案 1 :(得分:0)
您可以执行以下操作。您为COUNT
使用了不必要的子查询。
SELECT DoctorsVisits.VisitDate, COUNT(*) As Total
FROM DoctorsVisits
WHERE DoctorsVisits.PeriodOfVisitId=2
GROUP BY DoctorsVisits.VisitDate