select 任务编号,企业编号 from 你的表 group by 任务编号,企业编号 having count(*)>1 and min(范围编号)<>max(范围编号)
------其他解决方案--------------------
select 任务编号,企业编号 from t
group by 任务编号,企业编号 having count(distinct 范围编号
)>1
------其他解决方案-------------------- WITH t AS (
select 1 ID ,'rw001' rw,'Qy001' qy, 1 fw from dual union all
select 2 ,'rw001','Qy002', 1 from dual union all
select 3 ,'rw001','Qy002', 2 from dual union all
select 4 ,'rw001','Qy004', 1 from dual union all
select 5 ,'rw002','Qy005', 1 from dual union all
select 6 ,'rw002','Qy004', 1 from dual union all
select 7 ,'rw002','Qy004', 1 from dual union all
select 8 ,'rw002','Qy008', 1 from dual union all
select 9 ,'Rw003','Qy011', 1 from dual union all
select 10,'Rw003','Qy012', 1 from dual union all
select 11,'Rw003','Qy013', 1 from dual union ALL
select 111,'Rw003','Qy013', 1 from dual union all
select 12,'Rw003','Qy014', 1 from dual )
SELECT rw,qy
FROM t t
GROUP BY rw,qy
HAVING COUNT(1)>1 AND NOT EXISTS (SELECT 1
FROM t a
GROUP BY rw,qy,fw
HAVING COUNT(1)>1 AND a.rw=t.rw) ------其他解决方案-------------------- intersect 试试 ------其他解决方案-------------------- INTERSECT 试试 ------其他解决方案--------------------