鉴于以下表格数据:
+------+---------+----------+----------+-------------+------------+-----------------+---------------------+
| id | version | quantity | state | orderLineId | locationId | stockMoveTaskId | created |
+------+---------+----------+----------+-------------+------------+-----------------+---------------------+
| 3277 | 0 | 2 | created | 169108 | 5692 | NULL | 2017-09-07 14:55:41 |
| 3073 | 0 | 2 | unpacked | 169108 | 5692 | NULL | 2017-09-07 09:40:35 |
+------+---------+----------+----------+-------------+------------+-----------------+---------------------+
使用MySQL - 如何删除包含状态'创建的所有行?只有当表格中还包含一个状态为' unpacked'给定订单行ID?
答案 0 :(得分:7)
您将使用delete
。 。 。与join
:
delete todelete
from t todelete join
t
on t.orderLineId = todelete.orderLineId
where todelete.state = 'created' and t.state = 'unpacked';