Welcome 微信登录

首页 / 数据库 / MySQL / Oracle group by的按照不同粒度聚合方法

一直以为group by 除了rollup和cube可以按照子句中指定的字段进行不同粒度的聚合,没有其他的方法了。今天因为groupby的bug(hash group b y)而发现了另一种方法,如下例:with tmp as(
    select "0001" userno, "01" pno from dual union all
    select "0001" userno, "01" pno from dual union all
    select "0001" userno, "02" pno from dual union all
    select "0002" userno, "01" pno from dual union all
    select "0002" userno, "03" pno from dual union all
    select "0003" userno, "03" pno from dual)
select grouping_id(userno, pno) gid, userno, pno, count(1) cnt
  from tmp
 group by grouping sets((), (userno), (userno, pno))其意义在于,我如果需要按照指定粒度进行汇总,而不用rollup或cube那种全组合的粒度,就可以用这种方式。Oracle表空间收缩方案Oracle特殊情况下数字四舍五入问题相关资讯      Oracle group by 
  • Oracle中group by用法  (04/01/2013 10:00:38)
本文评论 查看全部评论 (0)
表情: 姓名: 字数