Last Updated: May 12, 2026
For this exercise, we will work with below data:
Write a query using conditional aggregation that pivots payments into one row per user with columns completed, refunded, and failed showing the count of payments in each status.
Using CROSS JOIN LATERAL with VALUES, write a query that unpivots the payments table to produce one row per (payment_id, metric, value) triple, where metric is either 'amount' or 'refund_amount'. Filter to payments made by user 3.