我想把每个表的第一笔数据的一个值存到另一个表里,更新第一个好使,第二个就不好使了,求高手帮忙
with t1 as
(
SELECT TOP 1 TAV
FROM Tin_FengXiangYuan order by 时间 desc
),
t2 as
(
SELECT TOP 1 TAV
FROM Tin_YiPinYuan order by 时间 desc
)
update ATable_Output set TinAV= t1.TAV from t1 where ATable_Output.StationID=0
update ATable_Output set TinAV= t2.TAV from t2 where ATable_Output.StationID=1
------解决思路----------------------
这么写可以不?
update ATable_Output set TinAV= t1.TAV from (
SELECT TOP 1 TAV
FROM Tin_FengXiangYuan order by 时间 desc) t1 where ATable_Output.StationID=0
update ATable_Output set TinAV= t2.TAV from (SELECT TOP 1 TAV
FROM Tin_YiPinYuan order by 时间 desc) t2 where ATable_Output.StationID=1
------解决思路----------------------
两个更新语句要用两个With
with t1 as
(
SELECT TOP 1 TAV
FROM Tin_FengXiangYuan order by 时间 desc
),
update ATable_Output set TinAV= t1.TAV from t1 where ATable_Output.StationID=0
;with t2 as
(
SELECT TOP 1 TAV
FROM Tin_YiPinYuan order by 时间 desc
)
update ATable_Output set TinAV= t2.TAV from t2 where ATable_Output.StationID=1