尝试选择具有最高时间戳值和最低 ID 值的 20 个项目?
我试图选择具有 20 个最高“TimeStamp”值的行,并从这 20 行中选择具有最低 ID 值的 1 行:
$result_last = mysql_query("SELECT * FROM (SELECT * FROM Events ORDER BY TimeStamp DESC LIMIT 20) ORDER BY ID ASC LIMIT 1");
上面的查询不起作用,但对我来说很有意义。这个查询有问题吗?
I am trying to select rows with the 20 highest 'TimeStamp' value, and from those 20 rows the 1 row with the lowest ID value:
$result_last = mysql_query("SELECT * FROM (SELECT * FROM Events ORDER BY TimeStamp DESC LIMIT 20) ORDER BY ID ASC LIMIT 1");
The above query doesn't work, but it makes sense to me. Is there something wrong with this query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
错误是
#1248 - 每个派生表都必须有自己的别名
,这确实是事实。这应该有效:The error is
#1248 - Every derived table must have its own alias
and this is indeed true. This should work:尝试这样的事情:
Try something like this: