zoukankan      html  css  js  c++  java
  • GROUPING的用法

    GROUPING

    Syntax

    grouping::=

    Text description of functions113.gif follows
    Text description of grouping


    Purpose

    GROUPING distinguishes superaggregate rows from regular grouped rows. GROUP BY extensions such as ROLLUP and CUBE produce superaggregate rows where the set of all values is represented by null. Using the GROUPING function, you can distinguish a null representing the set of all values in a superaggregate row from a null in a regular row.

    The expr in the GROUPING function must match one of the expressions in the GROUP BY clause. The function returns a value of 1 if the value of expr in the row is a null representing the set of all values. Otherwise, it returns zero. The datatype of the value returned by the GROUPING function is Oracle NUMBER.

    See Also:

    group_by_clause of the SELECT statement for a discussion of these terms

    Examples

    In the following example, which uses the sample tables hr.departments and hr.employees, if the GROUPING function returns 1 (indicating a superaggregate row rather than a regular row from the table), then the string "All Jobs" appears in the "JOB" column instead of the null that would otherwise appear:

    SELECT DECODE(GROUPING(department_name), 1, 'All Departments',
       department_name) AS department,
       DECODE(GROUPING(job_id), 1, 'All Jobs', job_id) AS job,
       COUNT(*) "Total Empl", AVG(salary) * 12 "Average Sal"
       FROM employees e, departments d
       WHERE d.department_id = e.department_id
       GROUP BY ROLLUP (department_name, job_id);
    
    DEPARTMENT                     JOB        Total Empl Average Sal
    ------------------------------ ---------- ---------- -----------
    Accounting                     AC_ACCOUNT          1       99600
    Accounting                     AC_MGR              1      144000
    Accounting                     All Jobs            2      121800
    Administration                 AD_ASST             1       52800
    Administration                 All Jobs            1       52800
    Executive                      AD_PRES             1      288000
    Executive                      AD_VP               2      204000
    Executive                      All Jobs            3      232000
    Finance                        FI_ACCOUNT          5       95040
    Finance                        FI_MGR              1      144000
    Finance                        All Jobs            6      103200
    .
    .
    .
    
  • 相关阅读:
    去除字符串中的重复字符
    .net生成的类,跨工程调用显示注释
    Flex 页面空白或Error #2032: 流错误处理办法
    读取点阵字库
    SQL多表联合查询(Access数据库表)
    MSComm不能触发MSComm1_OnComm()事件原因之一
    一个小时内学习SQLite数据库(转)
    人生无悔
    学习之道
    挺经
  • 原文地址:https://www.cnblogs.com/jimeper/p/692313.html
Copyright © 2011-2022 走看看