--■■■model句を使う方法(10g以降)■■■
select soeji as YesNo,cntA,cntB
from YesNoTable
model return updated rows
dimension by(cast(RowNum as varchar2(3)) as soeji)
measures(ColA,ColB,0 as cntA,0 as cntB)
rules(
cntA['yes'] = count(decode(ColA,'yes',1))[any],
cntB['yes'] = count(decode(ColB,'yes',1))[any],
cntA['no'] = count(decode(ColA,'no' ,1))[any],
cntB['no'] = count(decode(ColB,'no' ,1))[any]);
--■■■union allを使う方法■■■
select 'yes' as YesNo,
count(decode('yes',ColA,1)) as cntA,
count(decode('yes',ColB,1)) as cntB
from YesNoTable
union all
select 'no',
count(decode('no',ColA,1)) as cntA,
count(decode('no',ColB,1)) as cntB
from YesNoTable;
--■■■外部結合を使う方法■■■
select a.YesNo,
count(decode(a.YesNo,b.ColA,1)) as cntA,
count(decode(a.YesNo,b.ColB,1)) as cntB
from (select 'yes' as YesNo from dual union all
select 'no' from dual) a
Left Join YesNoTable b
on a.YesNo in(b.ColA,b.ColB)
group by a.YesNo;