我有这张桌子:
rowId --- bussId
------------------
1 120
2 86
3 86
4 251
5 245
6 301
7 301
我想得到:
我怎么能这样做?
答案 0 :(得分:2)
1.) select Count(distinct bussid) from table
2.) select count(bussId) from table Group by bussId having Count(bussId)>1
答案 1 :(得分:0)
如果要计算重复项,则可以使用子查询:
select count(*)
from (select bussid, count(*) as numrows
from table t
group by bussid
) t
where numrows > 1;
您似乎找到了第一个问题的解决方案,但您可以将两者放在一个查询中:
select count(*) as Answer1, sum(numrows > 1) as Answer2
from (select bussid, count(*) as numrows
from table t
group by bussid
) t;