gpt4 book ai didi

mysql - SQL删除基于来自同一个表的查询的行?

转载 作者:行者123 更新时间:2023-11-30 22:55:49 25 4
gpt4 key购买 nike

给出这个查询:

SELECT cur.`id`
FROM `current` AS cur
LEFT OUTER JOIN (
SELECT MAX(EndDay_id.id) as id, EndDay_id.server_id
FROM current as EndDay_id
GROUP BY server_id, gameday
) AS EndDay
ON cur.id = EndDay.id
WHERE EndDay.id IS null

如何从表 'current' 中删除其 id 字段在上一个查询结果集中的行?

最佳答案

试试这个

DELETE cur FROM `current` AS cur
LEFT OUTER JOIN (
SELECT MAX(EndDay_id.id) as id, EndDay_id.server_id
FROM current as EndDay_id
GROUP BY server_id, gameday
) AS EndDay
ON cur.id = EndDay.id
WHERE EndDay.id IS null

我测试了它,这应该可以工作:http://sqlfiddle.com/#!2/a47c81

关于mysql - SQL删除基于来自同一个表的查询的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26440500/

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