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
Is there any difference between the primary key and unique key?
Is truncate autocommit?
What does set rowcount do?
What is log shipping? Can we do logshipping with SQL Server 7.0 - Logshipping is a new feature of SQL Server 2000. We should have two SQL Server - Enterprise Editions. From Enterprise Manager we can configure the logshipping. In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and we can use this as the DR (disaster recovery) plan.
What is the partitioning method?
How to copy data from one table to another table?
Why functions are used in sql server?
How can we check the sql server version?
Which command is used for user defined error messages?
1.how to find the dead lock in sql server? 2.How to fine the memory leaks in sql server? 3.suppose transaction log file increasing what action will take ?
What are system databases into sql server (2005/2008) : sql server database administration
What is parameterized reports in ssrs ?
What are blobs, tables, and Queues? Is SQL is the standard way to query blobs, tables, and queues?
Explain what are the database objects? : SQL Server Architecture
What is the use of tempdb? What values does it hold?