Search ⌘K
Amazon
Amazon

Foundations Track · Medium · 25 min

05 Medium Amazon Highest Grossing Items

-- highest grossing items -- WITH top_sales AS ( SELECT category, product, SUM(spend) AS total_spend FROM product_spend WHERE DATE_PART('year', transaction_d...

Foundations Track
Medium
25 min
aggregation

Company labels are directional practice context, not official interview guidance.

Timer 00:00
Back to practice

Objective

Practice aggregation through a Amazon-tagged business scenario.

Approach

Use this track to lock in clean query structure, basic filtering logic, and confidence with grouped output.

Company context

Company labels are directional practice context, not official interview guidance.

Prereq: query basics
Prereq: filtering

-- highest grossing items -- WITH top_sales AS ( SELECT category, product, SUM(spend) AS total_spend FROM product_spend WHERE DATE_PART('year', transaction_date) = 2022 GROUP BY category, product ), top_sales_ranking AS ( SELECT category, product, total_spend, DENSE_RANK() OVER(PARTITION BY category ORDER BY total_spend DESC) AS product_rank FROM top_sales ) SELECT category, product, total_spend FROM top_sales_ranking WHERE product_rank <= 2;

Pro question
This is a Pro question

Upgrade to Pro to unlock this prompt, the SQL workspace, and all 254 problems.

Upgrade to Pro — unlock all 254 problems
Editor
SQL workspace

Run queries against the protected question data, then submit once the result shape looks right.

Sign in to run SQL

Create a free account or sign in before running queries against protected question data.