问题描述
|
我正在尝试选择\'TimeStamp \'值最高的20行,并从那20行中选择ID值最低的1行:
$result_last = MysqL_query(\"SELECT * FROM (SELECT * FROM Events ORDER BY TimeStamp DESC LIMIT 20) ORDER BY ID ASC LIMIT 1\");
上面的查询不起作用,但对我来说有意义。这个查询有问题吗?
解决方法
错误是is1ѭ,的确如此。这应该工作:
$result_last = mysql_query(\"SELECT * FROM (SELECT * FROM Events ORDER BY TimeStamp DESC LIMIT 20) AS T ORDER BY ID ASC LIMIT 1\");
,尝试这样的事情:
$result_last = mysql_query(\"SELECT * FROM Events WHERE TimeStamp IN(SELECT TimeStamp FROM Events ORDER BY TimeStamp DESC LIMIT 10\") ORDER BY TimeStamp ASC LIMIT 1);