SQL-WHERE AGGREGATE> 1 [英] SQL - WHERE AGGREGATE>1
本文介绍了SQL-WHERE AGGREGATE> 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
想象一下,我有一个客户数据库表,其中包含{id,username,firstname,lastname}
Imagine I have a db table of Customers containing {id,username,firstname,lastname}
如果我想查找多少个具有不同名字的实例,可以这样做:
If I want to find how many instances there are of different firstnames I can do:
select firstname,count(*) from Customers group by 2 order by 1;
username | count(*)
===================
bob | 1
jeff | 2
adam | 5
我如何编写相同的查询以仅返回多次出现的名字?例如,在上面的示例中,仅返回jeff和adam的行。
How do I write the same query to only return firstnames that occur more than once? i.e. in the above example only return the rows for jeff and adam.
推荐答案
您希望具有
子句,像这样:
select
firstname,
count(*)
from Customers
group by firstname
having count(*) > 1
order by 1
这篇关于SQL-WHERE AGGREGATE> 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文