Welcome Back

Google icon Sign in with Google
OR
I agree to abide by Pharmadaily Terms of Service and its Privacy Policy

Create Account

Google icon Sign up with Google
OR
By signing up, you agree to our Terms of Service and Privacy Policy
Instagram
youtube
Facebook

Running Total of Payments per Customer

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: