我有一张桌子:
sid sname status
101 abc pass
102 cda fail
103 fgh pass
104 hij pass
105 jqk fail
106 lfj fail
我希望输出为:
sid sname status
101 abc fail
102 cda pass
103 fgh fail
104 hij fail
105 jqk pass
106 lfj pass
答案 0 :(得分:2)
select
sid,
sname,
case
when status = 'pass' then 'fail'
when status = 'fail' then 'pass'
else null
end as 'status'
from tableX
答案 1 :(得分:0)
UPDATE Table
SET Status = CASE Status WHEN 'pass' THEN 'fail' ELSE 'pass' END
GO
SELECT *
FROM Table
GO
或者:
UPDATE Table
SET Gender = IIF(Gender = 'pass', 'fail', 'pass')
GO
SELECT *
FROM Table
GO