有进货表一个,有商品资料表一个,有库存资料表一个,
怎样把进货表的进货数量写进库存表里?
假设商品资料表里有10个商品记录,但是,库存表里只有5个商品记录,
而进货表里却有6个记录,已有记录的增加库存数量就容易
而库存表里没有的记录,要怎样写SQL语句增加资料和库存啊?
怎样把进货表的进货数量写进库存表里?
假设商品资料表里有10个商品记录,但是,库存表里只有5个商品记录,
而进货表里却有6个记录,已有记录的增加库存数量就容易
而库存表里没有的记录,要怎样写SQL语句增加资料和库存啊?
update ...
else
insert into ...
商品资料表t2(Id)
库存资料表t3(Id,qty)添加商品:
Insert into t2(Id) select Id from t1 where not exists(select 1 from t2 where t1.Id=t2.Id)
添加库存:
Insert into t3(Id,qty) select Id,qty from t1 where not exists(select 1 from t3 where t1.Id=t3.Id)