ORACLE PIVOT TABLE EXAMPLE

Imagine you have a table as shown below:
----------------------------------------------
EmpName    Post              City
---------------------------------------------
Ravi              Manager      Newyark
peter             Worker        London
Ram              Manager      Newyark
--------------------------------------------
If you are able to get a report as shown below, then it is Pivot table:
-------------------------------------------------
City              Manager      Worker
------------------------------------------------
Newyark      2                   0
London         0                   1
-----------------------------------
That is,  values in the rows (such as Manager,worker) have become the FIELD NAMES.
Then it will be called as Pivot Table.

How this can be achieved in oracle sql :

SELECT CITY, SUM(CASE POST WHEN 'Manager' THEN 1 ELSE 0 END) AS 'MANAGER',
               SUM(CASE POST WHEN 'Worker' THEN 1 ELSE 0 END) AS 'WORKER'
                From  EMP
               GROUP BY CITY;
Thank you spending your time here.
If possible you; can leave some comments or suggestions.
Thanks a lot once again.
Google Search
Disclaimer and Copy Right