create table TEST1(
WK char(5),
KBN char(1),
DATE1 number(8),
DATE2 number(8));
insert into TEST1 values('GRP-A','8',20050627,20050624);
insert into TEST1 values('TGRP' ,'8',20050623,20050621);
insert into TEST1 values('GRP-A','8',20050623,20050616);
insert into TEST1 values('GRP-A','8',20050622,20050627);
insert into TEST1 values('TGRP' ,'8',20050620,20050623);
insert into TEST1 values('GRP-A','3',null ,20050630);
insert into TEST1 values('GRP-B','8',20050617,20050622);
insert into TEST1 values('TGRP' ,'8',20050624,20050621);
insert into TEST1 values('GRP-B','8',20050623,20050620);
insert into TEST1 values('GRP-B','3',20050623,20050627);
insert into TEST1 values('GRP-C','3',null ,20050623);
insert into TEST1 values('TGRP' ,'8',20050622,20050615);
insert into TEST1 values('GRP-C','8',20050624,20050620);
commit;
select WK,総件数,納期遅,
to_char(trunc(納期遅/総件数*100,1),'999.9') || '%' as 率
from (select decode(grouping(WK),1,'全体',WK) as WK,
count(*) as 総件数,
sum(case when DATE1 > DATE2 then 1 else 0 end) as 納期遅
from TEST1
where WK Like 'GRP%'
and KBN='8'
group by rollup(WK))
order by decode(WK,'全体',1,0),WK;