PDA

View Full Version : MYSQL Fiscal year type


bojiokia
04-13-2007, 04:03 AM
This is the SQL statment to generate by calender year type... which mean
from the january to December...

String sql = "SELECT TO_CHAR(REQUEST_DATE, 'MM') AS MONTH, SUM(REQUEST_TYPE)
AS HITS " +
"FROM REQUEST " +
"WHERE BRANCH=? AND CATEGORY=? " +
"AND TO_CHAR(REQUEST_DATE, 'YYYY')=? " +
"GROUP BY TO_CHAR(REQUEST_DATE, 'MM')";

I need the SQL statment to generate by fiscal year type...
Which is from the 1 April 06 to 31 March 07

just like when i choose 1st April 07, it will show me 1 April 07 to 31 March 08

Any one could help? its giving me a headache.
*cheers*

Fumigator
04-13-2007, 07:47 PM
Assuming a column that is properly defined as a date type, you can do this:

SELECT SUM(REQUEST_TYPE) as hits
FROM REQUEST
WHERE BRANCH=? AND CATEGORY=?
AND REQUEST_DATE BETWEEN ('2007-04-01' AND date_add('2007-04-01' interval 1 year)

(Substitute that hard-coded date with your variable)