Oracle Database 10g SQL Fundamentals II - Practice 4
개발 및 관리/Oracle 9i, 10g, 11g, 12c, 19c 2012. 11. 14. 07:37
Oracle Database 10g SQL Fundamentals II - Practice 4
4. Generating Reports by Grouping Related Data
1)
SELECT MANAGER_ID
, JOB_ID
, SUM(SALARY)
FROM EMPLOYEES
WHERE MANAGER_ID < 120
GROUP BY ROLLUP(MANAGER_ID, JOB_ID)
;
2)
SELECT MANAGER_ID
, JOB_ID
, SUM(SALARY)
, GROUPING(MANAGER_ID)
, GROUPING(JOB_ID)
FROM EMPLOYEES
WHERE MANAGER_ID < 120
GROUP BY ROLLUP(MANAGER_ID, JOB_ID)
;
3)
SELECT MANAGER_ID
, JOB_ID
, SUM(SALARY)
FROM EMPLOYEES
WHERE MANAGER_ID < 120
GROUP BY CUBE(MANAGER_ID, JOB_ID)
;
4)
SELECT MANAGER_ID AS MGR
, JOB_ID AS JOB
, SUM(SALARY)
, GROUPING(MANAGER_ID)
, GROUPING(JOB_ID)
FROM EMPLOYEES
WHERE MANAGER_ID < 120
GROUP BY CUBE(MANAGER_ID, JOB_ID)
;
5)
SELECT DEPARTMENT_ID
, MANAGER_ID
, JOB_ID
, SUM(SALARY)
FROM EMPLOYEES
GROUP BY
GROUPING SETS
((DEPARTMENT_ID, MANAGER_ID, JOB_ID)
, (DEPARTMENT_ID, JOB_ID)
, (MANAGER_ID, JOB_ID)
)
;
'개발 및 관리 > Oracle 9i, 10g, 11g, 12c, 19c' 카테고리의 다른 글
Oracle Database 10g SQL Fundamentals II - Practice 6 (0) | 2012.11.14 |
---|---|
Oracle Database 10g SQL Fundamentals II - Practice 5 (0) | 2012.11.14 |
Oracle Database 10g SQL Fundamentals II - Practice 3 (0) | 2012.11.14 |
Oracle Database 10g SQL Fundamentals II - Practice 1 (0) | 2012.11.14 |
ORACLE GRANT CONNECT, RESOURCE 그리고 FLASHBACK (0) | 2012.11.13 |