I am currently getting this output from my query:-
Count(Total)| Type1
-----------------
24 T1
22 T2
But I want the output like this:-
T1 T2
----------
24 22
Note that Type1 column can contain any values like T1,T2,T3 so I cannot fix the values in the query. I am using Oracle 10g, how can I do it?
Oracle 10g does not have a
PIVOTfunction so you can use an aggregate with aCASE:See SQL Fiddle with Demo
Or you can implement this directly into a query similar to this, using the
SUM()aggregate will count each occurrence that matches thetype1value in theCASEstatement:If you have an unknown number of values to transform into columns, then you will want to use a procedure similar to this:
Then to execute it: