我想更新列表中未选择其ID的用户的所有记录。有关如何正确执行以下查询的任何建议吗?
UPDATE credit SET val = 0
WHERE u_id not in (SELECT u_id FROM credit WHERE type = 10 and month(create_m)=5)
答案 0 :(得分:0)
为什么需要选择查询才能执行此操作。试试这个。
UPDATE credit SET val = 0
WHERE type <> 10
and month(create_m)<>5
当Not In
返回任何sub-query
值时, 更新 NULL
子句将失败,因此请使用Not Exists
UPDATE C SET val = 0
FROM credit C
WHERE NOT EXISTS (SELECT 1
FROM credit C1
WHERE C.u_id =C1.u_id
AND C1.type = 10
AND month(C1.create_m)=5)
答案 1 :(得分:0)
您使用的条件不相等:<>
:
UPDATE credit SET val = 0
WHERE type <> 10 OR month(create_m) <> 5