巴拉巴拉1234 回复 助人为乐(提问者)我理解的好像是这个思路
SELECT
a.*
,sum(b.num) AS \'月累计\'
,sum(b.num)/a.use_month*12 AS \'除以月数乘12\'
FROM (
SELECT
YEAR(date1) AS use_year
,MONTH(date1) AS use_month
,DATE_FORMAT(date1,\'%Y-%m\') AS YM
,sum(day) AS \'当月\'
FROM ahead_date
GROUP BY use_year,use_month
) a
LEFT JOIN (
SELECT
YEAR(date1) AS use_year
,MONTH(date1) AS use_month
,sum(day) AS num
FROM ahead_date
GROUP BY use_year,use_month
) b ON a.use_year=b.use_year AND a.use_month>=b.use_month
GROUP BY a.YM