假设我有一个客户数据库表,其中包含 {id,username,firstname,lastname}
如果我想找出有多少个不同名字的实例,我可以这样做:
select firstname,count(*) from Customers group by 2 order by 1;
username | count(*)
===================
bob | 1
jeff | 2
adam | 5
如何编写相同的查询以仅返回出现多次的名字?即在上面的示例中只返回 jeff 和 adam 的行。
最佳答案
你想要 having
子句,像这样:
select
firstname,
count(*)
from Customers
group by firstname
having count(*) > 1
order by 1
关于SQL - WHERE 聚合> 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1213004/