【发布时间】:2021-05-02 08:10:26
【问题描述】:
如果 order_no 在今天发货的表中,我想使用 sql 在查询中将订单状态更改为发货。 (我使用 ms 访问)
【问题讨论】:
如果 order_no 在今天发货的表中,我想使用 sql 在查询中将订单状态更改为发货。 (我使用 ms 访问)
【问题讨论】:
您可以使用where 子句。例如:
update orders
set State = 'shipped'
where order_no in (select ts.order_no from todayshipped as ts);
您可能需要添加 and State <> 'shipped' 以避免更新已发送的行。
出于性能原因,我经常建议使用exists:
update orders
set State = 'shipped'
where exists (select 1
from todayshipped as ts
where ts.order_no = orders.order_no
);
这可以轻松利用todayshipped(order_no) 上的索引。
【讨论】: