任何一個幫我請請計算兩行或更多行記錄見下面的查詢。計算黑白兩行
SELECT docs_DocCode, SUM(invd_Qty) AS Total_IN
FROM dbo.SI_InventoryDetail
WHERE (docs_DocCode = 'D.C') AND (itm_ItemCode = '0101050000083') OR
(docs_DocCode = 'STO') AND (itm_ItemCode = '0101050000083') OR
(docs_DocCode = 'SAO') AND (itm_ItemCode = '0101050000083') OR
(docs_DocCode = 'IOB') AND (itm_ItemCode = '0101050000083') OR
(docs_DocCode = 'GRN') AND (itm_ItemCode = '0101050000083') OR
(docs_DocCode = 'STI') AND (itm_ItemCode = '0101050000083') OR
(docs_DocCode = 'SAI') AND (itm_ItemCode = '0101050000083') OR
(docs_DocCode = 'SRN') AND (itm_ItemCode = '0101050000083') OR
(docs_DocCode = 'PRN') AND (itm_ItemCode = '0101050000083')
GROUP BY docs_DocCode
上述查詢給我的結果如下
dics_doccode Total
D.C 328.00000000
GRN 205.00000000
IOB 96.00000000
SAI 66.00000000
SAO 51.00000000
SRN 14.00000000
STI 150.00000000
STO 150.00000000
現在,我想補充(特區+ STI + SAI) - (GRN + STI + SAI + IOB)=一個值
,我使用SQL SERVER 2000
Thankx
親愛THankx的快速回復,但你給出的查詢工作不 – 2010-12-14 06:07:37
我我要在哪裏添加Cluse在這裏確定我的ITEM基本計算是針對當前股票狀態.... – 2010-12-14 06:11:34
@Brave ali Khatri:'不工作'是不夠的詳細描述一個問題。我不能得到你的完整的第二評論:-S – zerkms 2010-12-14 06:14:43