mysql:之间选择

时间:2010-11-11 13:27:24

标签: mysql sql mysql-error-1111

我无效使用群组功能,不确定问题出在哪里

预期结果是从最大可用

开始的xxx秒内的时间戳列表

请指教。

SELECT timestamp, response_time 
FROM results
WHERE id = XYZ AND timestamp between 
(SELECT MAX(timestamp) FROM results inn WHERE id = 22) AND 
(SELECT timestamp FROM results WHERE id =22 AND timestamp = MAX(timestamp) - XXX)
ORDER BY timestamp DESC

谢谢

1 个答案:

答案 0 :(得分:2)

SELECT  timestamp, response_time
FROM    results
WHERE   id = @xyz
        AND timestamp BETWEEN
        ( 
        SELECT  MAX(timestamp)
        FROM    results
        WHERE   id = 22
        ) AND
        ( 
        SELECT  MAX(timestamp)
        FROM    results
        WHERE   id = 22
        ) - @xxx
ORDER BY
        timestamp DESC

确保您在(id, timestamp)上有一个索引,以便快速工作。