Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

What is explicit mode in sql server?

1109


What is sql azure database?

206


What is sqlcmd?

1136


Do you know what is sql injection?

1041


How to convert numeric values to integers in ms sql server?

1159


How do I view a script in sql server?

1086


How to generate create procedure script on an existing stored procedure?

1062


What is row_number () and partition by in sql server?

1133


How to change server name in sql server?

1252


What are the different authentication modes in sql server? How can it be changed?

1139


Difference between report and query parameter.

1144


Can we linked SharePoint to a SQL database?

1073


What are types of storage modes? : sql server analysis services, ssas

1082


what is the system function to get current user's user id? : Sql server database administration

1047


How to list all objects in a given schema?

1106