PIVOT query in Oracle

Pivot query in Oracle 

report generated each hour wise   for zone and circle in the following query


 select *
    from (
   select  ZONE,CIRCLE,TO_NUMBER(to_char(ococ_dt,'hh24'))  grp,count(*) cnt
    from OCOC_CAF_JAN2022 
      group by  ZONE,CIRCLE,TO_NUMBER(to_char(ococ_dt,'hh24'))
               )
   pivot(
    sum(cnt)
     for grp in ( 0 as "00-01",1 as "01-02",2 as "02-03",
                  3 as "03-04",4 as "04-05",5 as "05-06",
                   6 as "06-07",7 as "07-08",8 as "08-09",
                   9 as "09-10",10 as "10-11",11 as "11-12",
                     12 as "12-13",13 as "13-14",14 as "14-15",
                       15 as "15-16",16 as "16-17",17 as "17-18",
                       18 as "18-19",19 as "19-20",20 as "20-21",
                       21 as "21-22",22 as "22-23",23 as "23-24"
                   ) )
   ORDER BY 1,2;

Output 




1 Comments

And that's all there is to it!

If anyone has any other questions or requests for future How To posts, you can either ask them in the comments or email me. Please don't feel shy at all!

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

Previous Post Next Post