select count(monthsList) as mTotal from (select DATE_FORMAT(aDate,'%c') as monthsList from (
select @maxDate - interval (a.a + (10 * b.a) + (100 * c.a)) month as aDate from
(select 0 as a union all select 1 union all select 2 union all select 3
union all select 4 union all select 5 union all select 6 union all
select 7 union all select 8 union all select 9) a,
(select 0 as a union all select 1 union all select 2 union all select 3
union all select 4 union all select 5 union all select 6 union all
select 7 union all select 8 union all select 9) b,
(select 0 as a union all select 1 union all select 2 union all select 3
union all select 4 union all select 5 union all select 6 union all
select 7 union all select 8 union all select 9) c,
(select @minDate := start_date, @maxDate := stop_date from table where id=1) d // เลข 1 คือค่าอ้างอิง record ครับ
) e
where aDate between @minDate and @maxDate) as allMonths where monthsList = 1 // เลข 1 หมายถึงหาจำนวนเดือน มกราคมครับ
ข้อ 2.
Code
select sum(point) as totalPoint from
(select DATE_FORMAT(aDate,'%c') as monthsList, if(DATE_FORMAT(aDate,'%c')=1,10,5) as point from (
select @maxDate - interval (a.a + (10 * b.a) + (100 * c.a)) month as aDate from
(select 0 as a union all select 1 union all select 2 union all select 3
union all select 4 union all select 5 union all select 6 union all
select 7 union all select 8 union all select 9) a,
(select 0 as a union all select 1 union all select 2 union all select 3
union all select 4 union all select 5 union all select 6 union all
select 7 union all select 8 union all select 9) b,
(select 0 as a union all select 1 union all select 2 union all select 3
union all select 4 union all select 5 union all select 6 union all
select 7 union all select 8 union all select 9) c,
(select @minDate := start_date, @maxDate := stop_date from table where id=1) d
) e
where aDate between @minDate and @maxDate) as allMonths
ปล. ถ้าเป็นไปได้ ใช้ PHP process เถอะครับ จะไวกว่ากันเยอะครับ