Running Total of Payments per Customer
payments Table:

Query Explanation:
● SELECT CustomerID, PaymentDate, Amount
– Retrieves the customer ID, date of payment, and payment amount.
● SUM(Amount) OVER (PARTITION BY CustomerID ORDER BY PaymentDate)
– Calculates a running total of payments for each customer.
– PARTITION BY CustomerID: Keeps the total separate per customer.
– ORDER BY PaymentDate: Accumulates the total in chronological order.
● AS RunningTotal
– Assigns a name to the calculated running total column.
SQL Query:
SELECT
CustomerID,
PaymentDate,
Amount,
SUM(Amount) OVER (PARTITION BY CustomerID ORDER BY PaymentDate) AS RunningTotal
FROM Payments;
Output:

