Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8221347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:53:07+00:00 2026-06-07T13:53:07+00:00

I have a products table with below schema (ProductID INT, ProductStartDate date, ProductExpDate date,

  • 0

I have a products table with below schema

 (ProductID INT, ProductStartDate date, ProductExpDate date, 
ProductTypeID int, #PacketsInProduct int, 
Price int, Discount int, Score int)

I need to write a query something like this in MongoDB. I am using C# driver 1.5. The problem I am getting in first CTE below (Products_CTE) where Row_NUMBER() is deciding the product rank which is matching my where conditions, based on the rank I need to filter the rows in 2nd CTE. All my where conditions are dynamic, Can anyone help me out here. Thanks in advance

;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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:53:08+00:00Added an answer on June 7, 2026 at 1:53 pm

    This query is going to require you building a map/reduce. Check to docs here: http://www.mongodb.org/display/DOCS/MapReduce.

    If you need some help constructing the map/reduce, let me know and I’ll do my best. I’d encourage you to try it yourself first though. Note that map/reduce isn’t for real time querying, so you’ll need to snapshot the results, which means you are working with eventually consistent data and the business needs to know about it and be ok with it.

    Furthermore, chances are that your schema could be optimized for this type of query depending on your needs. Storing data in mongodb the same way you store it in a relational database is almost never the right choice. If it is the right choice, then chances are you should stick with a relational model anyways.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my DB I have the products table (ID int, ... , Sponsored bool)
I have table 'products' and I need to update 'price' field by 20% if
I have three tables, Products(ProductID, ProductName) Orders(OrderID, OrderDate) OrderDetails(ProductID, OrderID) Junction table between Products
I have a table that stores the price of various products and would like
I have a many-to-many relation with a linked table. See (simplified) schema below. Created
I have table called products with columns: productid , productname, productprice categoryid My problem
I have a student marks table with schema as given below: Student -------- SNO
I have 3 tables with values like below **tbl_product** recID pID price colour 1
I have a products table which contains information about products. Each products can have
I have a products table with a column of type SET (called especialidad), with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.