我想从 reg_data3 中选择常规数据并获取平均月份值并插入平均值表作为更新,但效果不佳。
SELECT
year(str_to_date(date, '%Y-%m-%d'))as year,
month(str_to_date(date, '%Y-%m-%d')) as month,
round(avg(evep),2),
round(Avg(sunshine_hrs),2),
round(sum(rainfall),2),
round(AVG(max_temp),2),
round(avg(min_temp),2)
FROM
reg_data3
GROUP BY
year(str_to_date(date, '%Y-%m-%d')),
month(str_to_date(date, '%Y-%m-%d'))
ORDER BY 1 Desc
UPDATE
avg_month_val
set
year='year' ,
month='month',
evep='evep' ,
sunshine_hrs='sun_shine_hrs',
rainfall='rainfall',
max_temp='max_temp',
min_temp='min_temp';
答案 0 :(得分:1)
试试这个:
UPDATE
avg_month_val
set
`year` = YEAR(STR_TO_DATE(`date`, '%Y-%m-%d')),
`month` = MONTH(STR_TO_DATE(`date`, '%Y-%m-%d')),
`evep` = ROUND(AVG(`evep`), 2),
`sunshine_hrs` = ROUND(AVG(`sunshine_hrs`) ,2),
`rainfall` = ROUND(SUM(`rainfall`), 2),
`max_temp` = ROUND(AVG(`max_temp`), 2),
`min_temp` = ROUND(AVG(`min_temp`), 2)
FROM
reg_data3
GROUP BY
MONTH(STR_TO_DATE(`date`, '%Y-%m-%d')),
MONTH(STR_TO_DATE(`date`, '%Y-%m-%d'))