oracle根據分組查百分比

zhenghaishu發表於2015-10-26
create table test20151026(id int, group_name varchar2(10));
insert into test20151026 values (1, 'A');
insert into test20151026 values (2, 'A');
insert into test20151026 values (3, 'A');
insert into test20151026 values (4, 'B');
insert into test20151026 values (5, 'B');
commit;

select group_name, sum_G, sum_G/total*100||'%' as rate from 
  (select group_name, sum(id) as sum_G from test20151026 group by group_name),
  (select sum(id) as total from test20151026);




來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29485627/viewspace-1816383/,如需轉載,請註明出處,否則將追究法律責任。

相關文章