From Rows to Columns: Using Oracle SQL PIVOT for Smarter Reports
Overview: Explain the PIVOT clause with aggregation. Example Query:
SQL> ed
1 SELECT *
2 FROM (
3 SELECT deptno, job, sal
4 FROM emp
5 )
6 PIVOT (
7 SUM(sal)
8 FOR job IN ('SALESMAN' AS SALES_REP, 'MANAGER' AS MGR)
9* );
SQL> /
DEPTNO SALES_REP MGR
_________ ____________ _______
30 4350 2850
10 2450
20 2975
Use Case: Creating executive summary tables.
No comments:
Post a Comment