select count(*),cartid from abc group by cartid having count(*)>2;
with temp as ( select 1 a,2 b,3 c from dual union all select 1,2,3 from dual union all select 1,3,3 from dual union all select 1,3,3 from dual union all select 1,3,3 from dual union all select 1,5,3 from dual union all select 1,6,3 from dual union all select 1,7,3 from dual) select a,b,c,rn from ( select a,b,c,count(1) rn from temp a group by a ,b,c having count(1)>1 ) b group by a,b,c
select cartid,count(cartid) from tb group by cartid having count(cartid)>2
SELECT cardid,COUNT(1) FROM tablename GROUP BY cardid HAVING COUNT(1) > 1;应该是2条及两条以上吧
这个sql在数据量大的情况不够优化,较消耗资源
SELECT cardid,COUNT(1) FROM tablename GROUP BY cardid HAVING COUNT(1) > 1up
(
select 1 a,2 b,3 c from dual
union all
select 1,2,3 from dual
union all
select 1,3,3 from dual
union all
select 1,3,3 from dual
union all
select 1,3,3 from dual
union all
select 1,5,3 from dual
union all
select 1,6,3 from dual
union all
select 1,7,3 from dual)
select a,b,c,rn from
(
select a,b,c,count(1) rn from temp a group by a ,b,c having count(1)>1
) b
group by a,b,c
select cartid,count(cartid) from tb group by cartid having count(cartid)>2