目前有个需求是在数据库里面查询表中数据值,
比如 table A中的keyword1,如果keyword1中存在“中国人”则保留在keyword1中,
否则把keyword1的内容保存到keyword2中,并删除keyword1中的字段。
求解法,可以直接通过sql语句实现不?

解决方案 »

  1.   

    update A
    set keyword2=keyword1,keyword1=null
    where keyword1 like '%中国人%'
      

  2.   

    hust_qb (firstar)
      '截至2010-09-05 01:31:32  用户结帖率0.00%当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
    http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
    http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html8、如何给分和结贴?
    http://community.csdn.net/Help/HelpCenter.htm#结帖
      

  3.   

    update A
    set keyword2=keyword1,keyword1=null
    where keyword1 not like '%中国人%'
      

  4.   

    update a
    set keyword2=keyword1,keyword1=null 
    where locate('中国人',keyword1)=0
      

  5.   

    update A
    set 
    keyword2=if(instr(keyword1,'中国人')=0,keyword1,keyword2)
    keyword1=if(instr(keyword1,'中国人')>0,keyword1,'')