我有一个表,其中有以下数据,我想跳过第3行,只想获取打开状态只有一次,我使用下面的查询,但它也跳过工作5。
SELECT t.*
FROM emailEvent t
JOIN
( SELECT MIN(id) AS minid
FROM emailEvent WHERE email_id = 3
GROUP BY status
) AS grp
ON grp.minid = t.id
WHERE (t.email_id = 3)
我提出了一个解决方案,但不确定是否有其他最好的解决方案
SELECT t.*
FROM emailEvent t
WHERE t.status != "Open" and t.email_id = 3
UNION
(
SELECT et.*
FROM emailEvent et
WHERE et.status = "Open" and et.email_id = 3
ORDER BY et.createdAt DESC LIMIT 1
)
我希望结果像这样
2条答案
按热度按时间f3temu5u1#
对于不支持窗口聚合的旧版本:
mu0hgdu02#
与
NOT EXISTS
: