PostgreSQL - Window Functions in PostgreSQL
Consider the table
What does this query return?
orders(order_id, customer_id, order_date, amount) with data:(1, 101, '2024-01-01', 100), (2, 101, '2024-01-02', 150), (3, 102, '2024-01-01', 200)What does this query return?
SELECT order_id, customer_id, amount, LAG(amount, 1, 0) OVER (PARTITION BY customer_id ORDER BY order_date) AS prev_amount FROM orders ORDER BY order_id;