Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have one requirement where the table will be like this

---------------------
Name | Amount |
---------------------
Raju | 2000 |
----------------------
Rajesh | 4000 |
----------------------
Raju | 4000 |
--------------------
Rajesh | 10000 |
----------------------

But i need a values where result set will be like this

------------------
Raju | Rajesh |
-----------------
6000 | 14000 |
-----------------



can anyone give me idea for this query?

What I have tried:

when i tried group by it will result like this

-------------------
|Raju | 6000 |
-----------------
Rajesh | 14000 |
-----------------
Posted
Updated 3-Aug-17 20:03pm
Comments
ZurdoDev 16-Jun-17 9:36am    
PIVOT might work.
AlwzLearning 19-Jun-17 18:36pm    
use PIVOT .. it transposes columns and rows.
Santoshkumar Pithani 4-Aug-17 2:14am    
Pivot might works better for converting unknown rows into columns.

1 solution

select
sum(case when name='Raju' then cast(amount as varchar(50)) end)as Raju,
sum(case when name='Rajesh' then cast(amount as varchar(50)) end)as Rajesh
from table_name;
 
Share this answer
 
v4
Comments
Santoshkumar Pithani 4-Aug-17 2:25am    
We can get solution by using group by, but its a waste of time.

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