MEDIUMVerified Real Interview• Data Analyst
Highest-Grossing Items in Each Category
Verified Source:Public Interview Experience
You are given a table of product transactions from Amazon's retail store in year 2026.
Write a query to identify the top 2 highest-grossing products within each category.
For each product, output:
categoryproducttotal_spend
Results should be ordered by category ascending, and then by total_spend descending.
Table:
product_spend(categoryVARCHAR,productVARCHAR,user_idINT,spendDECIMAL,transaction_dateTIMESTAMP)
Execution Sandbox:
Your query executes inside an isolated in-memory PostgreSQL engine (PGlite WebAssembly). You have full access to standard PostgreSQL aggregations, window functions, and CTEs.
Standard SQL (ANSI)|Ln 1, Col 1(7 lines, 119 chars)
Tab Indent⌘↵ Run Query
Ready to execute. Press Run (⌘+Enter)
Write your query and click “Run” or press ⌘+Enter to inspect output.