update 里面需要用到 avg()函数, sql提示不能用,有什么好办法么?
sql:
update
aa
set
aa.FourWeekSaleAVG=avg(td.売上数)
from
OPENDATASOURCE(
'SQLOLEDB ',
'Data Source=server;User ID=sa;Password= ').ff.td
where
aa.BranchCode=td.店CD and
td.年週 between @YZs and @YZe
(aa.EntryType=2 and td.JAN=aa.ItemCode) or
(aa.EntryType=4 and td.JAN=aa.ItemCodeOld)
group by
td.JAN,td.店CD
报错的时候说,update 的set 里面不能用集合函数,有什么其它的代替方法么?一次就可一个更新进去的,谢谢!!
------解决方案--------------------try
update
aa
set
aa.FourWeekSaleAVG=td.売上数
from
aa,
(Select td.JAN,td.店CD,avg(td.売上数) As 売上数
From
OPENDATASOURCE(
'SQLOLEDB ',
'Data Source=server;User ID=sa;Password= ').ff.td
Where
td.年週 between @YZs and @YZe
group by
td.JAN,td.店CD) td
where
aa.BranchCode=td.店CD and
((aa.EntryType=2 and td.JAN=aa.ItemCode) or (aa.EntryType=4 and td.JAN=aa.ItemCodeOld))