我有產品表& priceDeatil表。Android sqlite/Ms sql/sql查詢
Prouct Table
ProductCode BusinessUnit
10001 ORB
10002 ORB
StockRecord Table
ProductCode Name StcokQuantity
10001 SUnSilk 1000
10002 Pen 500
priceDeatil
ProductCode BusinessUnit price DateFrom DateTo
10001 ORB 12.00 12-08-2011 31-09-2015
10001 ORB 21.00 01.08-2011 15-09-2011
10002 ORB 54.00 21.08-2011 15-09-2011
我想要得到的產品表中的記錄,StockRecords的表&價格與產品的最新價格
這裏PRODUCTCODE 10001包含2條記錄,當我運行查詢它返回2個reords.I想只有一個記錄。
SELECT WMProduct.BusinessUnit, WMProduct.ProductCode, StockRecord.Name, WMPriceDetail.Price
FROM WMProduct INNER JOIN StockRecord
ON WMProduct.ProductCode = StockRecord.ProductCode
INNER JOIN WMPriceDetail
WMPriceDetail ON WMProduct.BusinessUnit = WMPriceDetail.BusinessUnit AND WMPriceDetail.ProductCode = WMProduct.ProductCode
WHERE (WMPriceDetail.DateFrom < GETDATE()) AND (WMPriceDetail.DateTo > GETDATE() OR
WMPriceDetail.DateTo = NULL)
該查詢返回
BusinessUnit ProductCode Name Price
ORB 10001 SunSilk 12.00
ORB 10001 SunSilk 21.00
但我只需要一個記錄.... BusinessUnit產品代碼名稱價格 ORB 10001夏士蓮21.00 ORB 10002筆54.00
從該查詢我不能放TOP 1
因爲有更多的表結合..加入
如果價格未在價格明細表中定義,則該記錄不應顯示在列表中。
請幫我....提前
沒有它的不工作... – Piraba
見上面更新 – Blootac