zoukankan      html  css  js  c++  java
  • oracle使用union all的语句只能使用列号来排序

    以下两个语句查询结果是一样的,但是前者只能使用列号来排序,性能上,后者高于前者。

    select p_org_no,org_type,sort_no,count(*),grouping(p_org_no),grouping(org_type),grouping(sort_no)
    from o_org group by p_org_no,org_type,sort_no 
     union all
    select p_org_no,null,sort_no,count(*),grouping(p_org_no),1,grouping(sort_no)
    from o_org group by p_org_no,sort_no
     union all
    select null,org_type,sort_no,count(*),1,grouping(org_type),grouping(sort_no)
    from o_org group by org_type,sort_no
     union all 
    select null,null,sort_no,count(*),1,1,grouping(sort_no)
    from o_org group by sort_no
    order by 1,2,3 ;
    ---结果等价为以下语句:
    select p_org_no,org_type,sort_no,count(*),grouping(p_org_no),grouping(org_type),grouping(sort_no) 
    from o_org group by
    grouping sets((p_org_no,org_type,sort_no),(p_org_no,sort_no),(org_type,sort_no),sort_no)
    order by p_org_no,org_type,sort_no ;

  • 相关阅读:
    pdf.js-----后端返回utf-8数据流,前端处理数据展示pdf
    正则表达式之去除前后空格
    ng之邮箱校验
    ng-校验重复并提示具体重复内容
    input 数值框处理
    逻辑之不重复
    ng -----监听变化($scope.$watch())
    js中document的用法
    php中12个魔术方法
    php 中const和 define的区别
  • 原文地址:https://www.cnblogs.com/caibird2005/p/1370892.html
Copyright © 2011-2022 走看看