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 / pradip jain

Pivot concept can be use

please correct this as it it near to correct.


SELECT
[2004] '2004',
[2005] '2005',
[2006] '2006'
FROM
(select year,amt from dbo.Pivot1) s
PIVOT
(
sum(amt )
FOR year IN ([2004],[2005],[2006])
) p


output is

2004 2005 2006
10 20 30

Is This Answer Correct ?    2 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why truncate is ddl command?

715


How to Insert multiple rows with a single insert statement?

744


What the different topologies in which replication can be configured?

719


What options are available to audit login activity? : sql server security

825


Explain primary key in sql server?

749






What are the extra roles available in msdb? : sql server security

843


How you can get the list of largest tables in a database?

688


What is the importance of three tier architecture?

813


What stored by the master?

716


Does sql server 2000 full-text search support clustering?

673


What are cursors in ms sql server?

789


Can we join two tables without primary key?

799


Why you need indexing? Where that is stored and what you mean by schema object? For what purpose we are using view?

672


Can you explain the disadvantages/limitation of the cursor?

674


What is the contrast between sql and pl/sql?

783