我是SQL语言中的新商家请帮助我从两个表中计算总和,一个是购买,第二个是销售 但导致库存错误 购买(TB)
itemcode itemname qty
1 1100 10
2 1110 15
3 1600 10
销售(TB)
itemcode itemname qty
1 1100 5
2 1110 10
股票(查询)作为结果
itemcode itemname qty
1 1100 ?
2 1110 ?
3 1600 ?
请为其库存结果安排合适的脚本 感谢
答案 0 :(得分:1)
插入库存(itemcode,itemname,qty) 选择项目代码,项目名称,总和(数量) 从 ( 选择itemcode,itemname,qty 从购买 联合所有 选择itemcode,itemname,qty 从出售 )s 按项目代码分组