I am using sqlserver, which has following table ,
id companyname credited used
----------------------------------------
1 ABC 100 0
2 ABC 10 0
3 BBB 0 10
4 BBB 0 10
5 BBB 100 0
6 BBB 10 0
My expected output as below
id companyname credited used sum_credited sum_used
--------------------------------------------------------------------------
1 ABC 100 0 110 0
2 ABC 10 0 110 0
3 BBB 0 10 0 20
4 BBB 0 10 0 20
5 BBB 100 0 110 0
6 BBB 10 0 110 0
I have used the below query in which i didnt get as espected output
SELECT id,companyname,Credited,Used, SUM(credited) 'Sum_Credited'
FROM tmptichistory1
GROUP BY id,companyname,Credited,Used
I want to find the sum of credited and used values and display it in different columns with original values as i mentioned in the first table. Any help is appreciable.