Window function — calculation across rows related to current row.
Functions:
Example:
1-- Rank customers by total orders2SELECT3 customer_id,4 SUM(amount) as total,5 RANK() OVER (ORDER BY SUM(amount) DESC) as rank6FROM orders7GROUP BY customer_id;89-- Running total10SELECT11 order_date,12 amount,13 SUM(amount) OVER (ORDER BY order_date) as running_total14FROM orders;
BA use: