#834

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_idsecond_largest
1200
2150
3400

Your query result will appear here