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
Why truncate is ddl command?
How to Insert multiple rows with a single insert statement?
What the different topologies in which replication can be configured?
What options are available to audit login activity? : sql server security
Explain primary key in sql server?
What are the extra roles available in msdb? : sql server security
How you can get the list of largest tables in a database?
What is the importance of three tier architecture?
What stored by the master?
Does sql server 2000 full-text search support clustering?
What are cursors in ms sql server?
Can we join two tables without primary key?
Why you need indexing? Where that is stored and what you mean by schema object? For what purpose we are using view?
Can you explain the disadvantages/limitation of the cursor?
What is the contrast between sql and pl/sql?