Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含 3 列的复合键的表
st_id, sj_id, order
并希望根据特定的 st_id 和 sj_id 并采用 max(order) 删除一行
能否请你帮忙?
据我所知,您需要分两步执行此操作(这是从内存中提取的,因此可能不会第一次编译):
DELETE FROM table WHERE st_id = my_st_id AND sj_id = my_sj_id AND order IN ( SELECT MAX(order) FROM table WHERE st_id = my_st_id AND sj_id = my_sj_id)
这样做是首先执行内部 (SELECT) 查询,返回最大顺序。然后将这些结果传递给执行删除的外部查询。