gpt4 book ai didi

mysql - 选择具有 dup 值的最近项目

转载 作者:行者123 更新时间:2023-11-29 14:43:38 26 4
gpt4 key购买 nike

鉴于以下信息,我如何在唯一的 paramscron_action_id 对上选择最新的订单项(基于 time_entered)还没被处决吗?

cron_schedule

enter image description here

例如,id 1、2和4具有相同的paramscron_action_id,所以我不需要选择所有3,只需选择id 4。id的原理相同3/5 和 7/8。

我只能做到这一点

SELECT *
FROM cron_schedule cs
INNER JOIN cron_actions ca
ON cs.cron_action_id = ca.cron_action_id
WHERE time_executed = 0
-- GROUP BY (params, cron_action_id) ?

这应该返回 id 为 4、5、6 和 8 的行

谢谢

最佳答案

SELECT t1.* 
FROM cron_schedule t1
INNER JOIN (SELECT params,
cs.cron_action_id,
Max(time_entered) AS time_entered
FROM cron_schedule cs
INNER JOIN cron_actions ca
ON cs.cron_action_id = ca.cron_action_id
WHERE time_executed = 0
GROUP BY params, cron_action_id) AS t2
ON t1.params = t2.params
AND t1.cron_action_id = t2.cron_action_id
AND t1.time_entered = t2.time_entered
INNER JOIN cron_actions ca2
ON t1.cron_action_id = ca2.cron_action_id
WHERE t1.time_executed = 0

关于mysql - 选择具有 dup 值的最近项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7474617/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com