SELECT DISTINCT DATE_FORMAT( ACTIVITY_DATE, '%Y-%m' ) AS DISDATE, COUNT( ACTIVITY_ID ) AS Count
FROM activity
GROUP BY DATE_FORMAT( ACTIVITY_DATE, '%Y-%m' )
select
case month(`activity_date`) when 1 then count(`activity_date`) else 0 end as `Jan`,
case month(`activity_date`) when 2 then count(`activity_date`) else 0 end as `Feb`,
case month(`activity_date`) when 3 then count(`activity_date`) else 0 end as `Mar`,
case month(`activity_date`) when 4 then count(`activity_date`) else 0 end as `Apr`,
case month(`activity_date`) when 5 then count(`activity_date`) else 0 end as `May`,
case month(`activity_date`) when 6 then count(`activity_date`) else 0 end as `Jun`,
case month(`activity_date`) when 7 then count(`activity_date`) else 0 end as `Jul`,
case month(`activity_date`) when 8 then count(`activity_date`) else 0 end as `Aug`,
case month(`activity_date`) when 9 then count(`activity_date`) else 0 end as `Sep`,
case month(`activity_date`) when 10 then count(`activity_date`) else 0 end as `Oct`,
case month(`activity_date`) when 11 then count(`activity_date`) else 0 end as `Nov`,
case month(`activity_date`) when 12 then count(`activity_date`) else 0 end as `Dec`,
year(`activity_date`) as `Year`
from activities group by year(`activity_date`), month(`activity_date`)
select
year(`ACTIVITY_DATE`) as `Year`,
case month(`ACTIVITY_DATE`) when 1 then count(`ACTIVITY_DATE`) else null end as `Jan`,
case month(`ACTIVITY_DATE`) when 2 then count(`ACTIVITY_DATE`) else null end as `Feb`,
case month(`ACTIVITY_DATE`) when 3 then count(`ACTIVITY_DATE`) else null end as `Mar`,
case month(`ACTIVITY_DATE`) when 4 then count(`ACTIVITY_DATE`) else null end as `Apr`,
case month(`ACTIVITY_DATE`) when 5 then count(`ACTIVITY_DATE`) else null end as `May`,
case month(`ACTIVITY_DATE`) when 6 then count(`ACTIVITY_DATE`) else null end as `Jun`,
case month(`ACTIVITY_DATE`) when 7 then count(`ACTIVITY_DATE`) else null end as `Jul`,
case month(`ACTIVITY_DATE`) when 8 then count(`ACTIVITY_DATE`) else null end as `Aug`,
case month(`ACTIVITY_DATE`) when 9 then count(`ACTIVITY_DATE`) else null end as `Sep`,
case month(`ACTIVITY_DATE`) when 10 then count(`ACTIVITY_DATE`) else null end as `Oct`,
case month(`ACTIVITY_DATE`) when 11 then count(`ACTIVITY_DATE`) else null end as `Nov`,
case month(`ACTIVITY_DATE`) when 12 then count(`ACTIVITY_DATE`) else null end as `Dec`
from activity group by year(`activity_date`), month(`activity_date`)
select
`Year`,
sum(`Jan`) as `Jan`,
sum(`Feb`) as `Feb`,
sum(`Mar`) as `Mar`,
sum(`Apr`) as `Apr`,
sum(`May`) as `May`,
sum(`Jun`) as `Jun`,
sum(`Jul`) as `Jul`,
sum(`Aug`) as `Aug`,
sum(`Sep`) as `Sep`,
sum(`Oct`) as `Oct`,
sum(`Nov`) as `Nov`,
sum(`Dec`) as `Dec`,
sum(`Total`) as `Total`
from
(select year(`ACTIVITY_DATE`) as `Year`,
case month(`ACTIVITY_DATE`) when 1 then count(`ACTIVITY_DATE`) else null end as `Jan`,
case month(`ACTIVITY_DATE`) when 2 then count(`ACTIVITY_DATE`) else null end as `Feb`,
case month(`ACTIVITY_DATE`) when 3 then count(`ACTIVITY_DATE`) else null end as `Mar`,
case month(`ACTIVITY_DATE`) when 4 then count(`ACTIVITY_DATE`) else null end as `Apr`,
case month(`ACTIVITY_DATE`) when 5 then count(`ACTIVITY_DATE`) else null end as `May`,
case month(`ACTIVITY_DATE`) when 6 then count(`ACTIVITY_DATE`) else null end as `Jun`,
case month(`ACTIVITY_DATE`) when 7 then count(`ACTIVITY_DATE`) else null end as `Jul`,
case month(`ACTIVITY_DATE`) when 8 then count(`ACTIVITY_DATE`) else null end as `Aug`,
case month(`ACTIVITY_DATE`) when 9 then count(`ACTIVITY_DATE`) else null end as `Sep`,
case month(`ACTIVITY_DATE`) when 10 then count(`ACTIVITY_DATE`) else null end as `Oct`,
case month(`ACTIVITY_DATE`) when 11 then count(`ACTIVITY_DATE`) else null end as `Nov`,
case month(`ACTIVITY_DATE`) when 12 then count(`ACTIVITY_DATE`) else null end as `Dec`,
count(`ACTIVITY_DATE`) as Total
from activity group by year(`activity_date`), month(`activity_date`))
as temp group by `Year`