查找 MySQL 行中存储的日期,在一个查询中查找该日期之后的所有条目
我有一个表存储用于限制速率的操作。我想要做的是获取具有“key_action”(启动速率限制时间的操作)的最新行,然后查找该日期之后的所有条目。
目前我能想到的唯一方法是使用两个查询:
SELECTcreated_at FROM actions WHERE key_action=1 ORDER BYcreated_at DESC LIMIT 1
SELECT * FROM 操作 WHEREcreated_at >=(来自查询 1 的created_at)
是否有将这两个查询合并为一个的方法?
I have a table that stores actions for rate-limiting purposes. What I want to do is fetch the newest row that has a 'key_action' (the action that starts the time for rate-limiting) and then find all entries after that date.
The only way I can currently think to do it is with two queries:
SELECT created_at FROM actions WHERE key_action=1 ORDER BY created_at DESC LIMIT 1
SELECT * FROM actions WHERE created_at >= (created_at from query 1)
Is there a was to combine these two queries into one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将查询 1 设为查询 2 的子查询。
You can make query 1 a subquery of query 2.
我原以为 @Joe Stefanelli 的答案是正确的,但 WHERE 语句中的子查询不允许限制。从这个解决方法,我整理了这个查询(未经测试)
I'd have thought @Joe Stefanelli's answer was right, but Limits are not allowed in subqueries in WHERE statement. From this workaround, I put together this query (not tested)