Back to problems

Find top-spend categories per customer with ranking

SQL · Amazon · Hard

Using the tables and data below, write a single ANSI SQL query (common table expressions are allowed; temporary tables are not) that reports, for every customer, the two product categories on which that customer spent the most money. For any (customer, category) pair, total_spend equals the sum of qty * unit_price over every order item that belongs to that pair, and earliest_order_date is the smallest order_date among that customer's orders that contain at least one item of…

Checking your access…