我有一个表 [applicants],其中包含以下字段:
1) MemberID 2) 尝试
我的一些尝试是NULL。
对于表中 MemberID 计数为 1 的行,我想将尝试字段更新为 0。
任何帮助表示赞赏。
我有一个表 [applicants],其中包含以下字段:
1) MemberID 2) 尝试
我的一些尝试是NULL。
对于表中 MemberID 计数为 1 的行,我想将尝试字段更新为 0。
任何帮助表示赞赏。
一般方法是
update applicants set
Attempts = 0
where
MemberID in (select t.MemberID from applicants as t group by t.MemberID having count(*) = 1) and
Attempts is null -- if you need it
在 sql server 中,您可以执行以下操作:
with cte as (
select *, count(*) over(partition by MemberID) as cnt
from applicants
)
update cte set
Attempts = 0
where cnt = 1 and Attempts is null
UPDATE applicants
SET Attempts = 0
WHERE MemberID IN
(SELECT MemberID FROM applicants GROUP BY MemberID HAVING COUNT(MemberID)=1)
AND Attempts IS NULL