create table table1011(
PT char(1),
KH char(3),
OH char(2),
KI number(2));
insert into table1011 values('A','XX1','H1',10);
insert into table1011 values('C','XX1','H1',10);
insert into table1011 values('D','XX1','H1',10);
insert into table1011 values('A','XX2','H1',11);
insert into table1011 values('A','XX1','H2',60);
insert into table1011 values('A','XX2','H2',60);
insert into table1011 values('A','XX3','H2',60);
insert into table1011 values('A','XX4','H2',60);
insert into table1011 values('A','XX5','H3',50);
insert into table1011 values('A','XX6','H3',50);
insert into table1011 values('A','XX7','H3',50);
insert into table1011 values('A','XX8','H3',51);
commit;
--■■■サブクエリを使う方法■■■
select PT,KH,OH,KI
from table1011
where OH in (select OH from table1011
group by OH
having count(distinct KI) >= 2)
order by OH,KI,PT,KH;
--■■■分析関数を使う方法■■■
select PT,KH,OH,KI
from(select PT,KH,OH,KI,
count(distinct KI) over(partition by OH) as KICount
from table1011)
where KICount >=2
order by OH,KI,PT,KH;