create Table ColTable(
Col1 char(4),
Col2 number(1),
Col3 number(1),
Col4 number(1));
insert into ColTable values('aaaa',1,1,1);
insert into ColTable values('aaaa',2,1,1);
insert into ColTable values('aaaa',3,1,1);
insert into ColTable values('bbbb',1,1,1);
insert into ColTable values('bbbb',2,1,2);
insert into ColTable values('cccc',1,1,1);
insert into ColTable values('cccc',2,2,1);
insert into ColTable values('dddd',1,1,1);
insert into ColTable values('dddd',2,2,2);
insert into ColTable values('eeee',1,1,1);
insert into ColTable values('eeee',2,2,2);
insert into ColTable values('eeee',3,3,3);
insert into ColTable values('ffff',1,1,1);
commit;
--■■■分析関数を使う方法■■■
select Col1,Col2,Col3,Col4
from (select Col1,Col2,Col3,Col4,
count(distinct Col3) over(partition by Col1) as Col3Count,
count(distinct Col4) over(partition by Col1) as Col4Count
from ColTable)
where 2 <= any(Col3Count,Col4Count);
--■■■相関サブクエリを使う方法■■■
select Col1,Col2,Col3,Col4
from ColTable a
where exists(select 1 from ColTable b
where b.Col1 = a.Col1
and (b.Col3 != a.Col3
or b.Col4 != a.Col4));