0

我有表 reg_data 3 我每天输入数据一个值。我想选择该值的平均值(值的总和/天数),但我需要一个月的降雨量......但这段代码不能正常工作。

SELECT 
    year(str_to_date(date, '%m/%d/%Y'))as year,
    month(str_to_date(date, '%m/%d/%Y'))as month,
    Avg(sunshine_hrs) as sunshine_hrs,
    AVG(max_temp) as max_temp
    sum(rainfall) as rainfall
    avg(evep) as evep 
    avg(min_temp) as min_temp
FROM
    reg_data3
GROUP BY
    year(str_to_date(date, '%m/%d/%Y')),
    month(str_to_date(date, '%m/%d/%Y'));

CREATE TABLE `reg_data3` (
 `date` varchar(10) NOT NULL default '',
 `time` time NOT NULL,
 `rainfall` float default NULL,
 `evep` float default NULL,
 `max_temp` float default NULL,
 `min_temp` float default NULL,
 `sunshine_hrs` float default NULL,
 PRIMARY KEY  (`date`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
4

1 回答 1

0

您需要在查询中指定的每个字段后添加逗号,最后一个除外。像这样:

SELECT 
    year(str_to_date(date, '%m/%d/%Y'))as year,
    month(str_to_date(date, '%m/%d/%Y'))as month,
    Avg(sunshine_hrs) as sunshine_hrs,
    AVG(max_temp) as max_temp,
    sum(rainfall) as rainfall,
    avg(evep) as evep,
    avg(min_temp) as min_temp
FROM
    reg_data3
GROUP BY
    year(str_to_date(date, '%m/%d/%Y')),
    month(str_to_date(date, '%m/%d/%Y'));
于 2013-11-21T20:56:08.060 回答