2

我试图从 3 列中获取最后 60 项的平均值,但我得到一个错误:

#1248 - Every derived table must have its own alias

这是查询:

SELECT AVG( Sensor1 ) , AVG( Sensor2 ) , AVG( Sensor3 ) 
FROM (

    SELECT Sensor1, Sensor2, Sensor3
    FROM temperatur
    ORDER BY Zeit DESC 
    LIMIT 0 , 60
)

我对我相信的别名很迷茫..

4

2 回答 2

4

MySQL 需要所有派生表和子查询的别名,而右括号后缺少别名:

SELECT AVG( d.Sensor1 ) , AVG( d.Sensor2 ) , AVG( d.Sensor3 ) 
FROM 
(
    SELECT Sensor1, Sensor2, Sensor3
    FROM temperatur
    ORDER BY Zeit DESC 
    LIMIT 0 , 60
) d --- add this
于 2013-04-10T23:40:44.723 回答
2

我猜是语法,但我相信你需要更多这样的东西:

从(

SELECT Sensor1, Sensor2, Sensor3
FROM temperatur
ORDER BY Zeit DESC 
LIMIT 0 , 60

) T

于 2013-04-10T23:40:49.177 回答