想象一下,我有一个包含 {id,username,firstname,lastname} 的客户数据库表
如果我想找出有多少不同名字的实例,我可以这样做:
select firstname, count(*) from Customers group by 2 order by 1;
firstname | count(*)
====================
bob | 1
jeff | 2
adam | 5
如何计算多次出现的名字的数量?在伪 sql 中它会是这样的:
select
COUNT(
firstname,
count(*) as num_occurrences
)
from
Customers
group by 2
having num_occurrences > 1;