nix, shell, perl, php, mysql and mac os x tips and tricks

Wednesday, June 18, 2008

Group records by month in mysql

SELECT
count(*) as REQUESTS,
DATE_FORMAT(date,"%a %b %e, %Y") as DATE,
date as DATE2,
MONTH( date ) as "MONTH OF THE YEAR"
FROM requests
WHERE date BETWEEN '2007-10-01' AND '2008-06-17'
GROUP BY "MONTH OF THE YEAR"
ORDER BY DATE2 ASC

No comments:

Post a Comment