如何过滤下面查询中的计数列,只显示计数>的行数1?
select FirstName, COUNT(*) as [CountTickets] from tblParkingTickets
group by FirstName
order by [CountTickets] desc
这不起作用:
select FirstName, COUNT(*) as [CountTickets] from tblParkingTickets
where [CountTickets] > 1
group by FirstName
order by [CountTickets] desc
由于
答案 0 :(得分:7)
HAVING
:
HAVING COUNT(*) > 1
分组前的 WHERE
过滤器(因此COUNT
并不意味着什么)。分组后HAVING
过滤。
答案 1 :(得分:0)
select * from (select FirstName, COUNT(*) mycount from tblParkingTickets
group by FirstName
order by 2 desc) where mycount > 1
试试这个