请教SQL语句的含义,多谢啦。

已到而立之年 2014-12-25 09:38:30
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语句是什么意思?请大神指点,谢谢啦。
...全文
224 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
已到而立之年 2014-12-26
  • 打赏
  • 举报
回复
多谢二位的帮助,其实还是没看懂。再慢慢学吧,非常感谢。
houyajin 2014-12-25
  • 打赏
  • 举报
回复

; 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条件。
Neo_whl 2014-12-25
  • 打赏
  • 举报
回复
一条更新语句,

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进行删选符合条件的记录

22,299

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧