从每日数据中选择月平均值(每日/无天数之和)

时间:2013-11-14 13:02:20

标签: mysql

我的代码是这样但第三行mm/dd/yyyy的错误我的数据库日期格式是这样的:

SELECT
     evep
     year(date='MM/dd/yyyy'),
     month(date='MM/dd/yyyy'),
     Avg(evep)
FROM
     Value
GROUP BY
    evep,
     year(date='MM/dd/yyyy'),
     month(date='MM/dd/yyyy');

1 个答案:

答案 0 :(得分:0)

使用STR_TO_DATE()将日期字符串转换为实际日期

SELECT
     evep,
     year(str_to_date(date, '%m/%d/%Y')),
     month(str_to_date(date, '%m/%d/%Y')),
     Avg(evep)
FROM
     Value
GROUP BY
    evep,
     year(str_to_date(date, '%m/%d/%Y')),
     month(str_to_date(date, '%m/%d/%Y'));