表 id name parent_id
   01 xx   
   02 yy  
   0101 aaa
   0102 bbb
   0203 ccc
给让后面3条数据的parent_id赋值,规则是0101、0102的parent_id=01,0203的parent_id=02,update语句怎么写啊,帮帮忙啊,谢谢

解决方案 »

  1.   

    update tablename tt
       set tt.parent_id = substr(tt.id,1,2)
     where length(tt.id) > 2;
      

  2.   

    表id num name parent_id 
      11 01 xx    
      12 02 yy   
      13 0101 aaa 
      14 0102 bbb 
      15 0203 ccc 
    给让后面3条数据的parent_id赋值,规则是0101、0102的parent_id=num为01的id,0203的parent_id=num为02的id,update语句怎么写啊,帮帮忙啊,谢谢sorry,上面写错了,不好意思,请哪位兄弟帮忙下
      

  3.   

    update tablename tt set tt.parent_id = (select id from tablename ttt where substr(tt.num,1,2) = ttt.num)
    where length(tt.num) > 2;
      

  4.   


    update tablename tt 
    set tt.parent_id = '0'+left(num,1) 
    where length(tt.num)  > 2;
      

  5.   

    update tmp_user.t1 
    set parent_id=substr(id,1,2)
    where length(id) >2;
    commit;