我創建了一個mysql查詢來生成我想要的結果。mysql查詢給出了五個表的錯誤結果
其實它給了我錯誤的結果。我的預期結果是通過從裝運庫存總和中減去銷售庫存的總和來獲得當前庫存。
我的數據庫表有:
items(itemId,itemUniqueNo,itemSize,itemColor....)
prices(itemPrice,presentPriceBoolean,items_itemId....)
shipments(shipmentDate,noOfPairs,items_itemId,sources_sourceId....)
sources(sourceId,sourceName.....)
solditems(quantitySold,items_itemId....)
我的查詢如下:
SELECT itemId,itemUniqueNo,itemSize,itemGender,itemColor,sourceName,itemPrice,sourceName,
(COALESCE(SUM(noOfPairs),0) - COALESCE(SUM(quantitySold),0)) AS quantityInStock
FROM(shoepalace.items
INNER JOIN shoepalace.prices ON items.itemId = prices.items_itemId AND presentPrice =1)
LEFT JOIN shipments ON shipments.items_itemId = items.itemId
INNER JOIN sources ON sources.sourceId = shipments.sources_sourceId
LEFT JOIN shoepalace.solditems ON items.itemId = solditems.items_itemId GROUP BY itemId
讓說:
itemId shipmentQuantity quantitySold finalQuantity(quantityInStock)
2 15 3 12
3 10 0 10
4 7 4 3
.......
感謝:
根據「讓我們說」其中一個表或最終結果是什麼?它似乎不匹配任何東西,所以我無法做到。您可能想要提供示例表(包含示例數據),查詢得到的結果以及要獲取的結果。因爲這是你的問題很難理解。 – Dijkgraaf