17,377
社区成员
发帖
与我相关
我的任务
分享
--偷学下杨哥的
已写入 file afiedt.buf
1 with tb as(
2 select 1 id,'003' code,1 type from dual union all
3 select 2,'003',1 from dual union all
4 select 3,'004',2 from dual union all
5 select 4,'005',3 from dual union all
6 select 5,'006',1 from dual union all
7 select 6,'006',1 from dual)
8 select code
9 from tb
10 where type=1
11 group by code,type
12* having count(id)>=2
SQL> /
COD
---
003
006
with tb as(
select 1 id,'003' code,1 type from dual union all
select 2,'003',1 from dual union all
select 3,'004',2 from dual union all
select 4,'005',3 from dual union all
select 5,'006',1 from dual union all
select 6,'006',1 from dual)
--以上为提供数据的语句
select code
from (select code,type,count(id) cnt from tb group by code,type)
where cnt>=2
COD
---
003
006
select id,code
from tab
where type='1'
group by code
having count(*)>2
select id,code
from tab
where type='1'
group by id
having count(*)>=2