SQL Server Update 链接修改和when的应用


一、自链接方式

update b1 set b1.money = b1.money + b2.money 
from (select * from wallet where type='余额') b1 inner join 
(select * from wallet where type='积分') b2 on b1.userId= b2.userId

二、表链接

update r set r.cEnable = 0 from 表1 r 
inner join 表2 t on t.cId = r.cId 
where r.cRow = 100

 三、When 在update 中的应用

update wallet
set money = case type when 0 then money - 100 
                      when 1 then money - 200 
                      else money - 50
                      end
where money > 1000

update wallet
set money = case  
              when money > 1000 and money < 1500 then money - 300
              when money > 1500 and money < 2500 then money - 500 
              else money - 100  
              end
where money > 1000

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM