SELECT t1.X,
t1.Item_Code,
t2.X,
t2.Item_Code
FROM (SELECT Sum(e.item_qty) AS X,
A.Item_Code
FROM [Item Master]A
INNER JOIN [Counter Issue Details] e
ON e.Item_Code = A.Item_Code
INNER JOIN [Counter Master] CM
ON CM.Counter_Code = e.Counter_Code
WHERE e.Item_Code = A.Item_Code
AND A.Type_Code = 0
GROUP BY A.Item_Code)t1,
(SELECT Sum(e.item_qty) AS X,
A.Item_Code
FROM [Item Master]A
INNER JOIN [Counter Return Details] e
ON e.Item_Code = A.Item_Code
INNER JOIN [Counter Master] CM
ON CM.Counter_Code = e.Counter_Code
WHERE e.Item_Code = A.Item_Code
AND A.Type_Code = 0
GROUP BY A.Item_Code)t2
蔭得到OUTPT已有沒有更好的方式來寫這個選擇查詢
X Item_Code Y Item_Code
--------------------------------------- --------------------------------------- --------------------------------------- ---------------------------------------
3998.000 1 2.00 11
2000.000 2 2.00 11
2000.000 3 2.00 11
2504.000 4 2.00 11
2384.000 5 2.00 11
2456.000 6 2.00 11
2372.000 7 2.00 11
4900.000 9 2.00 11
2000.000 10 2.00 11
3948.000 11 2.00 11
現在我正在重複記錄的商品代碼11 2的所有10條記錄。 我希望將Y值映射到物品代碼11本身,其他所有物品都應該爲零
請使用t1和t2之間的連接 –
你想完成什麼?我可能會建議你問另一個問題(這個問題已經有答案),並解釋你在做什麼,提供樣本數據和期望的結果。 –