Show each customer's second-largest order on the CRM card
On the CRM customer card we want to show their «second-largest order» — used in spend-stability analytics. If the customer has fewer than two orders, the value is empty. For every customer find the amount of their second-largest order, one row per customer. Hint: the window function that pulls the N-th value from a window requires explicitly widening the window frame to the entire partition — otherwise the default frame truncates the right edge and the value at the second position can't be resolved correctly. Sort by customer id.
Expected output sample
This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables.
| customer_id | second_largest |
|---|---|
| 1 | 200 |
| 2 | 150 |
| 3 | 400 |
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign in