我有一个sql更新查询如下:
update #tree c
set treetop=p.treetop,
treeptag=p.treeptag,
adjust= 'a2a'
from #tree p ,#regions r
where c.treeptag=''
and c.xsreg=r.Region
and c.xsreg <> c.reg
and c.tradedate=p.tradedate
and p.treeaotag=replace(r.srvid+':'+c.tradedate+':'+c.litag,' ','')
我正在尝试在不使用“fromlist”的情况下使用连接编写查询,如下所示:
update #tree c
set treetop=(select p.treetop from #tree p ,#regions r
where c.treeptag=''
and c.xsreg=r.Region
and c.xsreg <> c.reg
and c.tradedate=p.tradedate
and p.treeaotag=replace(r.srvid+':'+c.tradedate+':'+c.litag,' ','')),
treeptag=(select p.treeptag from #tree p ,#regions r
where c.treeptag=''
and c.xsreg=r.Region
and c.xsreg <> c.reg
and c.tradedate=p.tradedate
and p.treeaotag=replace(r.srvid+':'+c.tradedate+':'+c.litag,' ','')),
adjust= 'a2a'
where exists (select 1 from #tree p ,#regions r where c.treeptag=''
and c.xsreg=r.Region
and c.xsreg <> c.reg
and c.tradedate=p.tradedate
and p.treeaotag=replace(r.srvid+':'+c.tradedate+':'+c.litag,' ',''))
然而,上面的查询似乎返回了不正确的行数;任何建议都是最有帮助的。