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


Please Help Members By Posting Answers For Below Questions

Give a example to search fr a string in all stored procedure in sql server.

696


Explain what is meant by replication of database?

719


What is the difference between ddl,dml and dcl commands?

810


How to create a user name in a database?

771


How do I perform an unattended install of sql server 2000?

757






What is the order in which the sql query is executed?

699


Do you have any idea about the tcl commands?

713


What is dirty page?

721


What is dml command?

713


What do you mean by a Composite primary key?

759


What is scalar user-defined function?

718


how to create “alternate row colour”?

128


What program is used to store the data source file?

671


What are a scheduled jobs or what is a scheduled tasks?

653


What is a natural primary key?

684