表 
-------------------------------------------------------------- 
id  name  sort 
1  aa    1 
2  bb    2 
3  cc    3 
4  dd    4 
5  ee    5 
6  ff    6 
7  gg    7 -------------------------------------------------------- 
如果我要将sort 7 变成 sort 2 ,2变成3,4变成4以此推 怎样实现用最少的update 语句,来完成。 
???????????????? 
---------------------------------------------------------------

解决方案 »

  1.   

    sort 7 变成 sort 2 ,2变成3,4变成4以此推这里找不到规律,不知道是什么意思
    怎么类推...是要将7改成2,然后7以前的都增加1吗。那么4就不是变成4了
      

  2.   

    如果我要将sort 7 变成 sort 2 ,2变成3,4变成4以此推 
      

  3.   

    update t
      set sort = decode(sort,1,1,7,2,sort+1)
      

  4.   

    update table1 set sort=case when sort=7 then 2 else sort+1 end
    where sort between 2 and 7
      

  5.   

    update t 
      set sort = decode(sort,7,2,sort+1) where sort between 2 and 7
      

  6.   

    update tb set sort = decode(sort,7,2,sort+1) where sort between 2 and 7;