insert Store(货号,库存数量,等级,存放位置,备注) select 货号 ,sum(库存数量) ,等级 ,存放位置 ,备注 from Detail t where not exists(select 1 from Store where 货号=t.货号) group by 货号,等级,存放位置 update A set 库存数量=B.库存数量 ,备注=B.备注 from Store A join ( select 货号 ,sum(库存数量) as '库存数量' ,等级 ,存放位置 ,max(备注) as '备注' from Detail t group by 货号,等级,存放位置 ) B on A.货号=B.货号 and A.等级=B.等级 and A.存放位置=B.存放位置
select 货号
,sum(库存数量)
,等级
,存放位置
,备注
from Detail t
where not exists(select 1 from Store where 货号=t.货号)
group by 货号,等级,存放位置
update A
set 库存数量=B.库存数量
,备注=B.备注
from Store A
join (
select 货号
,sum(库存数量) as '库存数量'
,等级
,存放位置
,max(备注) as '备注'
from Detail t
group by 货号,等级,存放位置
) B on A.货号=B.货号
and A.等级=B.等级
and A.存放位置=B.存放位置