我想:
首先总结两个表中的库存数据。
当我汇总第二个表并将数据插入汇总表时。
在重复的关键情况下,我想加上2库存。
谢谢你的帮助!
delete from 02_inventory.tempinvsummary;
insert into 02_inventory.tempinvsummary
(select pn,
sum(if(tp='Coil',no,0)) as 'coil',
sum(if(tp='Blank',no,0)) as 'blank',
sum(if(tp='Press',no,0)) as 'press',
sum(if(tp='Assy',no,0)) as 'assy' ,
sum(if(tp='Robot',no,0)) as 'robot'
from inventory
group by pn);
insert into 02_inventory.tempinvsummary
(select pn,
sum(if(tp='Coil',no,0)) as 'suplcoil',
sum(if(tp='Blank',no,0)) as 'suplblank',
sum(if(tp='Press',no,0)) as 'suplpress',
sum(if(tp='Assy',no,0)) as 'suplassy' ,
sum(if(tp='Robot',no,0)) as 'suplrobot'
from suplinventory
group by pn)
on duplicate key update
'====================
'prbly need codes here
coil=coil+suplcoil ????
'====================
select * from 00_masterdata.itemmaster, 02_inventory.tempinvsummary
where 00_masterdata.itemmaster.pn= 02_inventory.tempinvsummary.pn;
1条答案
按热度按时间w46czmvw1#
假设你的table看起来有点像这样
您可以合并并汇总这两个表,然后像这样对重复的表进行测试和更新
结果
但如果只需要将临时表连接到00\u masterdata.itemmaster,我不认为您需要临时表
例如
在这里,我使用一个名为users in my db的方便表来说明这一点
结果