熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> SQL語言 >> 正文

深入講解如何使用rollup配合group by命令

2013-11-13 12:35:35  來源: SQL語言 

  Oracle數據庫中的rollup配合group by命令使用可以提供信息匯總功能(與小計相似)

  示例如下

  SQL> select jobdeptnosal from emp;
  JOB DEPTNO SAL
  
  CLERK
  SALESMAN
  SALESMAN
  MANAGER
  SALESMAN
  MANAGER
  MANAGER
  ANALYST
  PRESIDENT
  SALESMAN
  CLERK
  CLERK
  ANALYST
  CLERK

  已選擇

  SQL> select jobdeptnosum(sal) total_sal
  from emp group by rollup(jobdeptno);
  JOB DEPTNO TOTAL_SAL
  
  ANALYST
  ANALYST
  CLERK
  CLERK
  CLERK
  CLERK
  MANAGER
  MANAGER
  MANAGER
  MANAGER
  PRESIDENT
  PRESIDENT
  SALESMAN
  SALESMAN
  

  已選擇

  SQL>


From:http://tw.wingwit.com/Article/program/SQL/201311/16203.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.