gpt4 book ai didi

sql-server - SQL Server 更新语句执行

转载 作者:搜寻专家 更新时间:2023-10-30 20:17:40 24 4
gpt4 key购买 nike

我只需要从顶部更新 2 行。

这里我使用的是更新语句

UPDATE orderDetails 
SET status = 56
WHERE OrderID IN (SELECT TOP 2 orderID
FROM orderDetails
WHERE station = 701)

但它正在更新所有行,不考虑 select 语句中的“TOP 2”。

最佳答案

试试这个:

update top (2) orderDetails 
SET status=56
WHERE ORDErID in (select orderID FROM orderDetails WHERE station=701)

或者你可以这样尝试:

;with cte as
(
select top 2 *
from orderDetails
WHERE station = 701
order by somecolumn --You need to specify the column on which you will make order by
)
update cte set status=56

关于sql-server - SQL Server 更新语句执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29411241/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com