ITPub博客

首页 > 数据库 > Oracle > oracle根据分组查百分比

oracle根据分组查百分比

原创 Oracle 作者:zhenghaishu 时间:2015-10-26 16:56:16 0 删除 编辑
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博客 ” ,链接:https://blog.itpub.net/29485627/viewspace-1816383/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-02-14

  • 博文量
    112
  • 访问量
    1057349