使用加入的两个表的总和

使用加入的两个表的总和

本文介绍了使用加入的两个表的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有两张桌子INStock和OUTStock。使用Join和Getting Current Stock合并这两个表..我已经完成了这样的查询.. SELECT DISTINCT (INStock.WareHouse) AS WH,INStock.ItemCode, SUM(INStock.Qty) AS INQty,SUM(OUTStock.Qty) AS OUTQty, SUM(INStock.Qty) - SUM(OUTStock.Qty) as 股票 FROM INStock 左 JOIN OUTStock ON INStock.ItemCode = OUTStock.ItemCode group by INStock.WareHouse,INStock.ItemCode 拥有 INStock.ItemCode = ' 0001' 但我无法获得如下所示的正确结果.. INSTOCK表 ------------------------ - WareHouse |代码|数量 ------------------------- 1 | 0001 | 5 1 | 5555 | 4 2 | 0001 | 6 3 | 0001 | 2 3 | 4444 | 2 ------------------------- OUTSTOCK表 -------- ------------------ WareHouse |代码|数量 ------------------------- 1 | 0001 | 3 1 | 5555 | 2 2 | 0001 | 3 2 | 4444 | 1 ------------------------- 我希望看起来像这样,(特殊代码) --------- ---------------------------------- WareHouse |代码| INQty | OutQty |股票 ------------------------------------------- 1 | 0001 | 5 | 3 | 2 2 | 0001 | 6 | 3 | 3 3 | 0001 | 2 | 0 | 2 ------------------------------------------ 请建议.. 解决方案 Hi, I Have Two Tables INStock and OUTStock. Merging these two Tables using Join and Getting Current Stock..I've done a query like this..SELECT DISTINCT (INStock.WareHouse) AS WH,INStock.ItemCode, SUM(INStock.Qty) AS INQty,SUM(OUTStock.Qty) AS OUTQty, SUM(INStock.Qty) - SUM(OUTStock.Qty) as StockFROM INStock Left JOIN OUTStock ON INStock.ItemCode = OUTStock.ItemCode group by INStock.WareHouse,INStock.ItemCode Having INStock.ItemCode='0001'But i Could not Get Correct Result Like Below..INSTOCK Table-------------------------WareHouse | Code | Qty------------------------- 1 | 0001 | 5 1 | 5555 | 4 2 | 0001 | 6 3 | 0001 | 2 3 | 4444 | 2-------------------------OUTSTOCK Table--------------------------WareHouse | Code | Qty------------------------- 1 | 0001 | 3 1 | 5555 | 2 2 | 0001 | 3 2 | 4444 | 1-------------------------I want to Look like this,(For Particular Code )-------------------------------------------WareHouse | Code | INQty | OutQty | Stock------------------------------------------- 1 | 0001 | 5 | 3 | 2 2 | 0001 | 6 | 3 | 3 3 | 0001 | 2 | 0 | 2------------------------------------------ Please Suggest.. 解决方案 这篇关于使用加入的两个表的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-21 00:23