All tasks

Top-3 Customers with Equality Handling

Intermediate

Amazon-level task. **Condition:** For each month, find the top-3 customers by order sum. If sums are equal, include all with the same rank. **Table:** ecommerce_orders (customer_id, order_date, total_amount, ...) **Requirements:** 1. Group by months (DATE_TRUNC) 2. Use DENSE_RANK for correct equality handling 3. Output month, customer_id, total_amount, rank **Hint:** DENSE_RANK() OVER (PARTITION BY month ORDER BY total DESC)

Category
Window Functions
Estimated time
~20 min
Databases
PostgreSQLGreenplum
Tags
FAANGInterviewDENSE_RANKTop-NRankingоконные функции

Sign in to solve

Start Solving