Sam Garber
Sam Garber

Reputation: 23

SQL Expression to Obtain Sum of All Payments on a Payment Schedule Table

I am trying to create a SELECT statement to obtain the sum of all payments due from a table that contains payment schedule. Fields include PaymentID, PaymentAmount, NumberofMonths. So for example, there are three rows:

PaymentId | PaymentAmount | NumberofMonths
==========================================
1         |  500          |  12
2         |  2000         |  8
3         |  1000         |  6

The total amount of all payments due would be $28,000.00. I'm a bit of a SQL/Oracle novice so I'm not sure how to get started with this.

Upvotes: 2

Views: 156

Answers (1)

Taryn
Taryn

Reputation: 247820

You can use the aggregate function SUM() and multiply the PaymentAmount by the NumberOfMonths:

select sum(PaymentAmount * NumberofMonths) Total
from yourtable

See SQL Fiddle with Demo

Upvotes: 2

Related Questions