Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grouping by Fiscal Year (Oracle)

Tags:

oracle

Is there a way in Oracle that can pull the FY? I used the script below to pull just two FY. Mytable date range is from FY1998 to FY2009.

 SELECT 'FY2008' as FY, 
         Site, 
         COUNT(*) 
    FROM mytable 
   WHERE date >='10-OCT-2007' 
     AND date <'10-OCT-2008' 
GROUP BY site

 SELECT 'FY2008' as FY, 
         Site, 
         COUNT(*) 
    FROM mytable 
   WHERE date >='10-OCT-2008' 
     AND date <'10-OCT-2009' 
GROUP BY site

Pulling two FY is OK but it's too much repeatative when pulling more than 10 FY.

like image 791
joe Avatar asked Oct 12 '10 19:10

joe


1 Answers

Add 83 days to your date and truncate it to whole year:

select 'FY'||TRUNC(date + 83, 'YYYY') as FY, Site, count(*)
from mytable
group by 'FY'||TRUNC(date + 83, 'YYYY'), site
like image 171
eumiro Avatar answered Sep 20 '22 12:09

eumiro