Skip to content
SHOPX-Q32Advanced

Top 3 products per category by revenue

For each category, return the 3 products with the highest revenue (quantity * unit_price - discount). Show category_name, product_name, revenue and its rank within the category.

CTEROW_NUMBERPARTITION BYTop-N per group

ShopX tables

Hints

Stuck? Reveal one hint at a time before looking at the answer.

Your answer

This is a workbook: your query is not run. Every model answer has been run against these tables.

How to approach this question

This is a advanced ShopX SQL interview question that practises CTE, ROW_NUMBER, PARTITION BY, Top-N per group. Read the schema first and note which table each column in the expected output comes from. Then decide whether you need a join, a filter, a grouping or a window function before you write any SQL.

Write your query in the answer box above, then compare it with the model answer and its checklist. Each model answer has been run against these tables. If you get stuck, reveal one hint at a time before you open the solution, which explains why the query works and lists common mistakes to avoid.

More free ShopX SQL questions

Want the other ShopX questions?

They are free too. Verify your email, create your account and practise every ShopX question, including the mock interview round.

Choose optional cookies

We use necessary cookies for account security. With your permission, we also use analytics and advertising cookies on marketing pages. See our Privacy Policy.