以下のスキーマを持つ製品テーブルがあります
(ProductID INT, ProductStartDate date, ProductExpDate date,
ProductTypeID int, #PacketsInProduct int,
Price int, Discount int, Score int)
MongoDBでこのようなクエリを書く必要があります。C#ドライバー1.5を使用しています。以下の最初のCTE(Products_CTE)で発生している問題。ここで、Row_NUMBER()は、2番目のCTEの行をフィルター処理する必要があるランクに基づいて、where条件に一致する製品ランクを決定しています。条件が動的であるすべての私の場所、誰かがここで私を助けることができますか?前もって感謝します
;WITH Products_CTE
AS
(
SELECT
ROW_NUMBER() OVER(PARTITION BY ProductID ORDER BY Score Desc, Price Asc) as RankByProduct,
*
FROM Products
WHERE
ProductID IN (1,2,3)
AND ProductTypeID IN (001,002)
AND [#PacketsInProduct] >3 and [#PacketsInProduct] <10
and ProductExpDate < GETDATE()
),
Products2_CTE
AS
(
SELECT
ROW_NUMBER() OVER (ORDER BY Score DESC, Price ASC) as rownum,
*
FROM Products_CTE
WHERE RankByProduct <= 3
)
SELECT
*
from Products2_CTE cte1
where rownum BETWEEN 15 AND 25
ORDER BY [Score] DESC, [Price] ASC