我正在加入表格,我的代码如下所示:
SELECT P.*
FROM (
SELECT ABC.StockCode
,ABC.Supplier
,ABC.Price
,MAX(ABC.OrigReceiptDate) ReceiptDate
FROM (
SELECT GRND.StockCode
,GRND.Supplier
,OrigReceiptDate
,(GRND.OrigGrnValue / GRND.QtyReceived) AS Price
FROM [SysproCompanyR].[dbo].[GrnDetails] GRND
WHERE QtyReceived > 0
) ABC
GROUP BY ABC.StockCode
,ABC.Supplier
,ABC.Price
) P
WHERE P.StockCode IN (
SELECT StockCode
FROM [SysproCompanyR].[dbo].[InvMaster]
)
ORDER BY P.StockCode
,P.Price
然而,结果集是:
我的问题是我需要获取最新购买的股票代码及其价格……但由于价格不同,我得到了重复的值,以帮助金发女郎>