Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hiii all,
i have atable that contains (id, name, commission)
i need to have the sum of commission where name=a as'first' and the sum where name=b as 'second' in the same row , any help, please?????

thanks
Posted
Comments
OriginalGriff 14-Mar-11 4:55am    
Sorry, that doesn't make a lot of sense.
Please edit your question and try to explain in better detail what you are trying to achieve.
Raj.rcr 14-Mar-11 4:58am    
Can u please explain in detail ?
moon2011 14-Mar-11 5:16am    
now i have atransaction (borrow and loan) i want to calculate the sum of loan for auser and the sum of borrower for the same user. all these data is in the same table, so i need arow tells me the accountId, Sum of Loan and the Sum of Borrower for him because i want to calculate the difference between them later.

Its not possible to add the values of rows, u can add the values of a column instead..

SQL
select sum(commission)  as 'First' from table1 where name='a'
union
select sum(commission)  as 'Second' from table1 where name='b'
 
Share this answer
 
Comments
Dalek Dave 14-Mar-11 5:23am    
Good Call.
moon2011 14-Mar-11 5:29am    
thanks for your help, but the result was one column 'First' only, why it doesn't appear the second???
Raj.rcr 14-Mar-11 7:19am    
I think, u may need the answer that costica has posted in the second solution.. Just a minor modification as in my code.. Follow the second solution..
moon2011 14-Mar-11 7:29am    
thanks alot for help
Raj.rcr 14-Mar-11 7:32am    
My pleasure..!
Try this
SQL
select  [First] = (select sum(commission) from table1 where name='a'),
        [Second] = (select sum(commission) from table1 where name='b')
 
Share this answer
 
Comments
moon2011 14-Mar-11 7:29am    
thanks
Costica U 14-Mar-11 7:37am    
You are welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900