我希望将reg_data3
列rainfall
的所有值的值加到去年的average_mas_curve
表列年,并将前几年的过去数据中的所有值作为总和但我想代表作为一年的最后一天的功能,请给我.......帮助我。
例如y-12-31
。
INSERT INTO mas_aver_curve (year, cumulative)
SELECT '2013-12-31', ROUND(SUM(rainfall), 1) rainfall
FROM reg_data3 G
WHERE date >= '2008-01-01' AND date < '2013-12-31'
答案 0 :(得分:1)
你可以尝试:
INSERT INTO mas_aver_curve (year, cumulative)
SELECT STR_TO_DATE(CONCAT(year(NOW())-1,'-12-31'),'%Y-%m-%d') AS LastDay,
ROUND(SUM(rainfall), 1) rainfall
FROM reg_data3 G
WHERE date >= '2008-01-01' AND date < '2013-12-31'
GROUP BY 1;
答案 1 :(得分:0)
也许您可以使用
选择年份和总和SELECT
YEAR(date),
ROUND(SUM(rainfall), 1)
FROM reg_data3
WHERE YEAR(date)>=2008 AND YEAR(date)<=2013
GROUP BY YEAR(date)
然后将其放入插页中。