Reputation: 216
I want to calculate total of particular column
For ex my table must looks like this
Customername Payment id RunningTotal
a 500 5 5
b 500 10 10
c 300 10 7
------ -----------
1300 22
I am getting the table but now I want to calculate the total mentioned at the end for the column Payment and RunningTotal.
Upvotes: 1
Views: 54553
Reputation: 1
select Customername ,id ,sum(Payment) as Payment , sum(RunningTotal) as RunningTotal from Table group by Customername ,id with rollup
Upvotes: 0
Reputation: 220
Without GROUPBY
clause use OVER()
Example:
select Customername, sum(Payment) OVER () AS TotalPayment, id, sum(RunningTotal) over()
as RunningTotal
from t1
Upvotes: 1
Reputation: 1000
SELECT Sum(Payment) AS Total FROM tablename;
Output: Total = 1300
Upvotes: 5
Reputation: 106
If you are getting the above result from table t1, then you can add your sum at the end by using an Union statement. Something like this
select Customername, Payment, id, RunningTotal
from t1
union all
select null,sum(payment),null,sum(runningtotal or any total)
from t1
This will add total payments and the other total at the end of the result.
Upvotes: 7
Reputation: 204766
select sum(Payment) as SumPayment, sum(RunningTotal) as SumRunningTotal
from yourTable
Upvotes: 1
Reputation: 1063
if you want to sum all rows, its as simple as:
select sum(payment) payment_sum, sum(runningtotal) runningtotal_sum
from customers;
Upvotes: 0