当前位置: 代码迷 >> Sql Server >> 请问SQL语句的含义,谢谢啦
  详细解决方案

请问SQL语句的含义,谢谢啦

热度:72   发布时间:2016-04-24 09:32:25.0
请教SQL语句的含义,多谢啦。
update sfc_proutingdres set baseQTYN=a.v
from 

select baseQTYN as v from sfc_operationres where operationid='1000000109'
) a 
where sfc_proutingdres.PRoutingDId in (select sfc_proutingdres.PRoutingDId from  sfc_proutingdres join  sfc_proutingdetail on sfc_proutingdres.PRoutingDId=sfc_proutingdetail.PRoutingDId where operationid='1000000109')


这个SQL语句是什么意思?请大神指点,谢谢啦。
------解决思路----------------------
一条更新语句,

update sfc_proutingdres set baseQTYN=a.v   --set 赋值语句 将后面查询中间结果看成表a,将a表中的字段v 赋值给sfc_proutingdres中的baseQTYN  where语句描述的是将sfc_proutingdres.PRoutingDId满足什么条件的记录才执行更新
from 

      select baseQTYN as v from sfc_operationres where operationid='1000000109'
) a   --表别名
where sfc_proutingdres.PRoutingDId in   --更新条件 
(select sfc_proutingdres.PRoutingDId from  sfc_proutingdres join  sfc_proutingdetail on sfc_proutingdres.PRoutingDId=sfc_proutingdetail.PRoutingDId where operationid='1000000109')--in()是一个相同属性值的集合,由两张表通过join联结,联结字段是on后面的表达式,where进行删选符合条件的记录

------解决思路----------------------

; with t as (
select sfc_proutingdres.PRoutingDId 
from  sfc_proutingdres join  sfc_proutingdetail
on sfc_proutingdres.PRoutingDId=sfc_proutingdetail.PRoutingDId 
where operationid='1000000109')  --- 要更新数据的条件之后
update sfc_proutingdres set baseQTYN=a.v
from ( 
select baseQTYN as v from sfc_operationres where operationid='1000000109' ) a  -- 被更新数据要取 字段
where sfc_proutingdres.PRoutingDId in (select  t.sfc_proutingdres from t 

这个语句的主要用处是想要更新sfc_proutingdres 的baseQTYN这个字段,但是这个字段的取值是这个表中 operationid='1000000109' 的值,所以才会有临时表的数据,不过他没有关联这个里面的值,所以'1000000109' 对应值是多个的话, sfc_proutingdres 的baseQTYN这个字段值会是operationid='1000000109'的baseQTYN值。 条件是sfc_proutingdres.PRoutingDId在临时表中的数据,也就是你最后的那个where条件。
  相关解决方案