mysql 通过对列应用筛选器(条件)删除多行[已关闭]

g52tjvyc  于 2022-12-26  发布在  Mysql
关注(0)|答案(1)|浏览(111)

2天前关闭。
Improve this question
输入:

| order_id | status      | order_date |
| -------- | ----------- | ---------- |
| ord1     | in_progress | 20221125   | 
| ord1     | in_progress | 20221126   | 
| ord1     | in_progress | 20221127   | 
| ord1     | shipped     | 20221128   | 
| ord2     | in_progress | 20221127   | 
| ord2     | in_progress | 20221128   | 
| ord2     | in_progress | 20221129   | 
| ord2     | in_progress | 20221130   | 
| ord3     | in_progress | 20221126   | 
| ord3     | picked_up   | 20221127   |

预期输出:

| order_id | status      | order_date |
| -------- | ----------- | ---------- |
| ord2     | in_progress | 20221127   | 
| ord2     | in_progress | 20221128   | 
| ord2     | in_progress | 20221129   | 
| ord2     | in_progress | 20221130   |

如何删除上例中订单的所有行,其中statusshippedpicked_up

wbgh16ku

wbgh16ku1#

自联接以检测具有要删除的状态的行:

delete t1 
from tab t1
join tab t2
on t1.order_id = t2.order_id
and t2.status in ('picked_up', 'shipped');

相关问题