gpt4 book ai didi

SQL UPDATE 具有复合主键的表中除某些行外的所有行

转载 作者:行者123 更新时间:2023-12-04 22:49:04 24 4
gpt4 key购买 nike

我正在为 SQL 语句苦苦挣扎。

我想在具有复合主键的表中更新除某些行之外的所有行。

这就是我现在所做的:

UPDATE Products SET Active = 0

_
UPDATE Products SET Active = 1
WHERE (Id_A = 1 AND Id_B = 1 AND Id_C = 1) OR
(Id_A = 1 AND Id_B = 2 AND Id_C = 1) OR
(Id_A = 5 AND Id_B = 8 AND Id_C = 3) OR
.
.
.
etc

这有效,但我不喜欢它。我希望能够一次性完成。

有没有办法在 SQL 中做到这一点?

最佳答案

你的意思是这样的:

UPDATE Products SET Active = CASE WHEN
(Id_A = 1 AND Id_B = 1 AND Id_C = 1) OR
(Id_A = 1 AND Id_B = 2 AND Id_C = 1) OR
(Id_A = 5 AND Id_B = 8 AND Id_C = 3) OR
.
.
.
THEN 1 ELSE 0 END

关于SQL UPDATE 具有复合主键的表中除某些行外的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12197712/

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