David Meyster Asked:2024-04-22 23:24:58 +0800 CST2024-04-22 23:24:58 +0800 CST 2024-04-22 23:24:58 +0800 CST 如何删除 SQL `upgrades` 表中 `first_item_id` 不唯一的所有元素? 772 任务非常简单,但解决方案并不明确,我多次询问神经网络,每个请求都有不同数量的受影响行 sql 1 个回答 Voted Best Answer CrazyElf 2024-04-22T23:32:31+08:002024-04-22T23:32:31+08:00 如果我没记错的话,通常会使用这样的东西: delete from upgrades as t1 where exists( select * from upgrades as t2 where t1.first_item_id=t2.first_item_id and t1.id>t2.id) 这是为了防止您需要删除并非所有此类元素并保留其中一个(第一个id)。 如果你直接删除所有它们,那么就像: delete from upgrades where first_item_id in (select first_item_id from upgrades group by first_item_id having count(*)>1)
如果我没记错的话,通常会使用这样的东西:
这是为了防止您需要删除并非所有此类元素并保留其中一个(第一个
id
)。如果你直接删除所有它们,那么就像: