在mysql中是否有任何函数用于表示最后一天

时间:2013-11-29 13:15:33

标签: mysql

我希望将reg_data3rainfall的所有值的值加到去年的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'

2 个答案:

答案 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;

sqlfiddle demo for the str_to_date part

答案 1 :(得分:0)

也许您可以使用

选择年份和总和
SELECT 
    YEAR(date), 
    ROUND(SUM(rainfall), 1) 
FROM reg_data3
WHERE YEAR(date)>=2008 AND YEAR(date)<=2013
GROUP BY YEAR(date)

然后将其放入插页中。