Reputation: 943
I made the below query and getting the following output.But the dates should not be consecutive,the new quater should start with next day.
SELECT x.* , end_dt-st_dt FROM
(SELECT 12-(LEVEL-1) AS Quater ,trunc(sysdate) - 90*LEVEL AS st_dt,trunc(sysdate) - 90*(LEVEL-1) AS end_dt
FROM dual
connect BY LEVEL <= 12
ORDER BY 1
) x
1 8/17/2011 11/15/2011 90
2 11/15/2011 2/13/2012 90
3 2/13/2012 5/13/2012 90
4 5/13/2012 8/11/2012 90
5 8/11/2012 11/9/2012 90
6 11/9/2012 2/7/2013 90
7 2/7/2013 5/8/2013 90
8 5/8/2013 8/6/2013 90
9 8/6/2013 11/4/2013 90
10 11/4/2013 2/2/2014 90
11 2/2/2014 5/3/2014 90
12 5/3/2014 8/1/2014 90
EXPECTED output :
....
...
10 11/2/2013 1/31/2014 90
11 2/1/2014 5/2/2014 90
12 5/3/2014 8/1/2014 90
Upvotes: 0
Views: 81
Reputation: 796
Is this is what you want? I am not sure
SELECT x.* , end_dt-st_dt FROM
(SELECT 12-(LEVEL-1) AS Quater ,
(CASE WHEN ( trunc(sysdate) - 90*LEVEL = TO_DATE('17-AUG-11','DD-MON-YY'))
THEN trunc(sysdate) - 90*LEVEL
ELSE trunc(sysdate)+1 - 90*LEVEL
END) AS st_dt,trunc(sysdate) - 90*(LEVEL-1) AS end_dt
FROM dual
connect BY LEVEL <= 12
ORDER BY 1
) x;
My output:
Upvotes: 1