update b
set 
qh=(select a.qh from a where a.qh=substr(b.tel,1,3))
dq=(select a.dq from a where a.qh=substr(b.tel,1,3))
where exist(select 1 from a,b where a.qh=substr(b.tel,1,3))

解决方案 »

  1.   

    select tel from b where exists(select 1 from a where qh=b.qh and dq=b.dq)
      

  2.   

    select tel from b where exists(select 1 from a where qh=a.qh and dq=b.dq)
      

  3.   

    update b set (qh,dq)=(
    select qh,dq 
    from a
    where a.qh=substr(b.tel,1,3)
    这个sql仍有些问题,不能处理非3位的区号
    如果表a,b都多一条记录qh='023X',处理起来会比较麻烦
      

  4.   

    update b
    set (qh,dq)=(select a.qh,a.dq from a where b.tel like a.qh || '%')
    where exist(select 1 from a where b.tel like a.qh || '%')
      

  5.   

    对!TwinkleCrystals(小雨点) 
      有前途!
      

  6.   

    建议:
    1.现对数据进行规范化处理;2.然后用
    update b set (qh,dq)=(
    select qh,dq 
    from a
    where a.qh=substr(b.tel,1,3);进行更新!
      

  7.   

    To: pumawang(想什么都学会!) 
      你说得有道理 我也查了 确实是这样
    To:  fffddd (杀我者死)  
      这个sql改为
      update b set (qh,dq)=
      (
       select qh,dq 
       from a
       where length(a.qh)=3 and a.qh=substr(b.tel,1,3) 
         or length(a.qh)=4 and a.qh=substr(b.tel,1,4)
      )
    即可!!
      

  8.   

    update b set (qh,dq)=
      (
       select qh,dq 
       from a
       where  a.qh=substr(b.b.tel,1,length(a.qh))  
     )
      

  9.   

    update b set (qh,dq)=
      (
       select max(qh),dq 
       from a
       where  a.qh=substr(b.b.tel,1,length(a.qh))  
       group by dq
     )
      

  10.   

    呵呵,ouygg(痞子酷) 聪明
    就这样就可以了 比我的简洁多了
      

  11.   

    其实在入数据库之前,你就可以运用手段对数据库的逻辑进行优化
    既然,你的区号都是三位的,那你在入数据库的时候,完全可以把它进行一个匹配
    如果,少了,就进行加0补充位数
    当然 ouygg(痞子酷) 的办法的确也是解决的办法之一
    不过,这不是解决根本的方法哟 !