我有兩張表,一張是商品資訊,一張是銷售額。我正在嘗試按專案和分支提取最后一個銷售訂單日期。
T1 ItemBranch: ItemNumber BranchPlant StockingType
T2 SalesDetail: SalesOrderNumber ItemNumber OrderDate SalesOrderType BranchPlant
我需要查詢 StockingType = S 和 SalesOrderType = SO 或 SD
同一個商品可以在多個分店銷售,我想要分店每個商品的最近訂購日期。
ItemNumber BranchPlant StockingType
33202332 649900 S
33202332 653003 S
33202332 644555 S
14590033 649900 S
T2 SalesDetail
SalesOrderNumber ItemNumber OrderDate SalesOrderType BranchPlant
16590 14590033 1/23/2020 SO 649900
17950 14590033 10/21/2021 SO 649900
17806 33202332 2/24/2021 SO 653003
18900 33202332 6/23/2021 SO 653003
18920 33202332 7/29/2016 SO 644555
Desired Result:
ItemNumber ItemBranch OrderDate
14590033 649900 10/21/2021
33202332 644555 7/29/2016
33202332 653003 6/23/2021
uj5u.com熱心網友回復:
您可以使用此查詢獲得所需的結果
SELECT t2.itemnum, t2.branchplant, MAX(t2.orderdate)
FROM t2
GROUP BY t2.itemnum, t2.branchplant;
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/429541.html
