每天MYSQL的平均值

时间:2014-11-19 01:59:15

标签: mysql sql mysqli

我想根据每天的温度值找到平均值。我怎么能这样做?

SELECT Timestamp, Value 
FROM aReadings 
WHERE type = 'Temperature' AND Timestamp BETWEEN ? AND ?

1 个答案:

答案 0 :(得分:2)

尝试:

SELECT DATE(Timestamp), AVG(Value)
FROM aReadings 
WHERE 
    type = 'Temperature' 
    AND Timestamp BETWEEN ? AND ?
GROUP BY DATE(Timestamp)

DATE(expr)提取日期或日期时间表达式expr的日期部分。