现在,数据库里有一个两个字段code   city
010
010
010
020
010
0721
0755现在要实现的功能是:
使用SQL语句,当code = 010 时,所有city 更新为北京
当code = 020 时,所有的city更新为上海

解决方案 »

  1.   

    update chinacode ste city=if(code ='010','北京',if(code ='020','上海',code))
      

  2.   

    update chinacode set city=if(code ='010','北京',if(code ='020','上海',code))
      

  3.   

    update tb
    set city=(case when code=010 then 北京  when code=020 then 上海 end)
      

  4.   


    update chinacode  set city=(case code when '010' then '北京' when '020' then '上海' end);
      

  5.   

    大家好,这个问题问错了。
    是更新 范围比如我要更新 code 为    100000-20000之间的数显示上海。
    20000001-3000000为北京。
      

  6.   

    20000001-3000000为北京。:20001-30000?
    update chinacode set city=if(code between 200001 and 30000,'北京',if(code between 100000 and 200000,'上海',code))
      

  7.   

    分开写更清晰update chinacode set city='北京' where code between 200001 and 30000;update chinacode set city='上海' where code between 100000 and 200000;
      

  8.   

    update chinacode  set city=(case code+0 when between 20000001 and 3000000  then '北京' when between 100000 and 20000 then '上海' end);我怀疑他的CODE字段是个字符串型的。
      

  9.   

    那里是这样呢?又要如何更新?
    mobile                                          SP
    13123456789                              联通
    139123456789                            移动
    就是说跟据前三位 将SP 更新为联通或者移动
    这又要怎么做?
      

  10.   

    update tt set SP=if(left(mobile='131','联通','移动'))OR
    将移动、联通头三位存入另一表中,与工作表连接替换
      

  11.   

    update tt set sp='联通' where left(mobile,3)='131';
    update tt set sp='移动' where left(mobile,3)='139';一贴一问。不要没完没了行么?
      

  12.   

    更正下11楼的
    update tt set SP=if(left(mobile,3)='131','联通','移动'))
      

  13.   

    update tt set SP=if(left(mobile='131',3),'联通','移动'))OR
    将移动、联通头三位存入另一表中,与工作表连接替换呵呵,写掉了
      

  14.   

    update table 
    set SP=case left(mobile,3) when 131 then '联通' when 132 '联通' when 139 then '移动' end