现在有表
Patient (ID,commid)
Community (commid,streetid)
Street (streetid,branchid)select ID,p.commid,s.streetid,s.branchid from Patient p,Community c,Street s
where p.commid = c.commid and c.streetid = s.streetid;把select出来的ID,p.commid,s.streetid,s.branchid 按照ID update进表
Grant(ID,commid,streetid,branchid)这句Update怎么写?

解决方案 »

  1.   

    -----try update a set a.commid=t.commid,a.streetid=t.streetid,a.branchid=t.branchid
    from Grant a inner join (
    select   ID,p.commid,s.streetid,s.branchid   
    from   Community c inner join Patient p on c.commid=p.commid
       inner join Street s  on c.streetid=s.streetid) t on a.id=t.id
      

  2.   

    update Grant set commid = A.commid,streetid = A.streetid,branchid = A.branchid
    from (select   ID,p.commid,s.streetid,s.branchid   from   Patient   p,Community   c,Street   s 
    where   p.commid   =   c.commid   and   c.streetid   =   s.streetid) A,Grant where Grant.ID = A.ID