0

How to add PIVOT in oracle 10g

select date,name,count(ID)
from
company
group by date,name

Below is the out of select query,

Date        Name     Count
---------   ------   -----
22-Dec-16   Create      92
23-Dec-16   Create      61
21-Dec-16   Create     135
26-Dec-16   Insert     241
19-Dec-16   Insert       1
26-Dec-16   Delete       1
18-Dec-16   Delete       1
26-Dec-16   Delete     304
25-Dec-16   Delete       1
21-Dec-16   ALTER        2
24-Dec-16   ALTER        3
25-Dec-16   ALTER        8
20-Dec-16   ALTER        1
23-Dec-16   ALTER        1
26-Dec-16   ALTER      791
19-Dec-16   ALTER        1
15-Dec-16   Modify       4
16-Dec-16   Modify      55
17-Dec-16   Modify      47
19-Dec-16   Modify      85
20-Dec-16   Modify     130
22-Dec-16   Modify     270
18-Dec-16   Modify      89
21-Dec-16   Modify     337
26-Dec-16   Modify    1743
23-Dec-16   Modify     373
24-Dec-16   Modify     766
25-Dec-16   Modify    3012

I need to add the PIVOT for the above query dynamically , Date into Columns,name into Row lobels and then sum of ID

Sum of Count    Column Labels                                               
Row Labels  15-Dec-16   16-Dec-16   17-Dec-16   18-Dec-16   19-Dec-16   20-Dec-16   21-Dec-16   22-Dec-16   23-Dec-16   24-Dec-16   25-Dec-16   26-Dec-16   Grand Total
ALTER                   1   1   2       1   3   8   791 807
Create                          135 92  61              288
Delete              1                           1   305 307
Insert                  1                           241 242
Modify  4   55  47  89  85  130 337 270 373 766 3012    1743    6911
Grand Total 4   55  47  90  87  131 474 362 435 769 3021    3080    8555
Gan
  • 197
  • 1
  • 4
  • 19
  • 2
    Possible duplicate of [How to do Pivoting in Oracle 10g](http://stackoverflow.com/questions/3386803/how-to-do-pivoting-in-oracle-10g) – Gurwinder Singh Dec 26 '16 at 14:54
  • When you say "dynamically" what do you mean? We could guess but it would be easier for everybody if just explained your requirements clearly. – APC Dec 26 '16 at 15:03

0 Answers0