两张表通过stockcode关联假设dtA字段 stockcode unitcost 存的是unitcost的历史记录,同一个stockcode有多条数据。
dtB 有一个字段 avgUnitcost,还有stockode,也可能存在同一个stockcode有多条数据,但是avgUntcost肯定是一样的。需求:用SQL语句更新dtB的所有avgUnitcost。sql
dtB 有一个字段 avgUnitcost,还有stockode,也可能存在同一个stockcode有多条数据,但是avgUntcost肯定是一样的。需求:用SQL语句更新dtB的所有avgUnitcost。sql
(select stockcode,avg(unitcost) as avgUnitcost from dtA group by stockcode)a
inner join dtB b on a.stockcode=b.stockcode
declare @a int
set @a=avg......
update a set....