如何编写以下SQL查询(SSMS)
我的表有2列 - ColumnA和ColumnB
IF my_table.columnA < 15
update my_table set my_table.ColumnB = 0
else IF my_table.columnA < 28
update my_table set my_table.columnB = 1
else IF my_table.columnA < 43
update my_table set my_table.columnB = 2
else IF my_table.columnA < 60
update my_table set my_table.columnB = 3
感谢您的帮助!
答案 0 :(得分:2)
您似乎想要一个case
表达式:
update mytable
set columnB = (case when columnA < 15 then 0
when columnA < 28 then 1
when columnA < 43 then 2
when columnA < 60 then 3
end)
where columnA < 60;