0

如何过滤下面查询中的计数列以仅显示计数 > 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

谢谢

4

2 回答 2

7

HAVING

HAVING COUNT(*) > 1

WHERE在 group by 之前过滤(因此COUNT没有任何意义)。HAVING分组后过滤。

于 2012-07-10T19:25:53.113 回答
0
select * from (select FirstName, COUNT(*) mycount from tblParkingTickets
group by FirstName  
order by 2 desc) where mycount > 1

试试这个

于 2012-07-10T19:27:10.227 回答