Hello all,
I have data like :-
year amt
2004 10
2005 20
2006 30
Now i want output as:-
2004 2005 2006
10 30 60
but i have to use here group by on year.So, i need a single
query within that i can find.
Answer Posted / sagun sawant
select ((select sum((case when year = '2004' then (amt)
else 0 end)) from account )) as [2004]
,((select sum((case when year = '2005' then (amt)
else 0 end)) from account )) as [2005]
,((select sum((case when year = '2006' then (amt)
else 0 end)) from account )) as [2006]
| Is This Answer Correct ? | 2 Yes | 2 No |
Post New Answer View All Answers
What are the advantages dts has over bcp?
What are three major types of constraints?
What is catalog views?
What is mssql?
When cursors are useful?
Tell me what do you understand by a view? What does the with check option clause for a view do?
tell me what are the steps you will take to improve performance of a poor performing query? : Sql server database administration
What is forward - only cursors / read only cursor?
In one interview...interviewer ask me question pleas tell me sql server architecture.. can any body tell me the sql server architecture with digram
How to assign null values to variables or columns?
How to test subquery results with the exists operator?
What is the security principal at the server level that represents your session?
What happens if strings are casted into wrong code pages in ms sql server?
What are three ways you can use an identity value inside a trigger? Why would you prefer one way over another?
How is SQL Azure different than SQL server?