码迷,mamicode.com
首页 > 其他好文 > 详细

如何将多条update语句合并为一条

时间:2014-09-24 16:10:17      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:style   div   2014   sp   c   line   r   bs   as   

需求:
如何将多条update语句合并为一条update语句:
如,update table1 set col=‘2012‘ where id=‘2014001‘
      update table1 set col=‘1009‘ where id=‘2014003‘
如何合并为一条?
 
在网上找了好久,总结了一个相对简单的语句(有些语句是函数语句,有点晕),如下:
  update table1 set col=(case id 
  when ‘2014001‘ then ‘2012‘
  when ‘2014003‘ then ‘1009‘ end)
  where  id in(‘2014001‘,‘2014003‘)
这个还可以扩展为多个字段的,这个你自己去依葫芦画瓢了~
 

如何将多条update语句合并为一条

标签:style   div   2014   sp   c   line   r   bs   as   

原文地址:http://www.cnblogs.com/klbc/p/3990413.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!