Query for extracting the data in pivot kind of format.
Hello PL/SQL Gurus,
I need to extract the data in a particular format from few tables using join condition. When I extract it using simple join then it returns me individual records based on condition but I want it in a particular format only.
When execute the query –
Select sf.JOIN_DT_KEY,sd.CLS,sd.CLS_STATUS,sf.CLS_QTY,sf.CLS_FEES,
sf.TOTAL_AMT
from stud_det_fact sf, stud_tag_dim sd, class_dim cd
where sf.stud_dim_key = sd.stud_dim_key
AND sf.alloc_cls_dim_key=d.alloc_cls_dim_key AND sd.CLS_STATUS IN
('BA','BSC','MA','MBA','MSC')
AND af.JOIN_DT_KEY between 20120404 and 20120410 ORDER BY sd.CLS
Than data is returned in following format –
JOIN_DT_KEY CLS CLS_STATUS CLS_QTY CLS_FEES TOTAL_AMT
1 20120404 BA WORKING 875 12 1050000
2 20120404 BA CAPITAL 125 12 150000
3 20120404 BA WORKING 875 12 1050000
4 20120404 BSC CAPITAL 4 10 4000
5 20120404 BSC CAPITAL 3 10 3000
6 20120404 MA WORKING 875 12 1050000
7 20120404 MA WORKING 1000 12 1200000
8 20120404 MBA ALGO 1000 12 1200000
9 20120404 MBA ALGO 1000 12 1200000
But I want it in following format using query itself –
JOIN_DT_KEY CLS WORKING (Qty) WORKING (Amt) CAPITAL(Qty) CAPITAL(Amt) ALGO(Qty) ALGO(Amt) NATURAL(Qty) NATURAL(Amt) GrandTotal(Qty) GrandTotal(Amt)
20120404 BA 1750 2100000 125 150000 0 0 0 0 1875 2250000
BSC 0 0 7 7000 0 0 0
0 7 7000
MA 1875 2250000 0 0 0 0 0
0 1875 2250000
MBA 0 0 0 0 2000 2400000 0
0 2000 2400000
Total 3625 4350000 132 157000 2000 2400000 0
0 5757 6907000
How to tweak the query to get the pivot kind of result, kindly help me. I appreciate all of your help in advance.
Thanks and i truly apperciate your help.
Note:- Attached is the sample excel sheet.
Edited by: user555994 on Apr 26, 2012 3:43 AM