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.

Answers were Sorted based on User's Feedback



Hello all, I have data like :- year amt 2004 10 2005 20 2006 ..

Answer / 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

Hello all, I have data like :- year amt 2004 10 2005 20 2006 ..

Answer / 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

Hello all, I have data like :- year amt 2004 10 2005 20 2006 ..

Answer / murali krishna reddy

SELECT A.YEAR, (SELECT SUM(AMT) FROM ACCOUNT WHERE YEAR <=
A.YEAR) AS AMT
FROM ACCOUNT AS A GROUP BY A.YEAR

How about this?

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More SQL Server Interview Questions

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

0 Answers  


How adventureworkslt tables are related?

0 Answers  


Is there any difference between the primary key and unique key?

0 Answers  


What gets stored inside msdb database?

0 Answers   Abacus,


How to set database to be read_only in ms sql server?

0 Answers  


How to give a user the option of importing Excel and a delimited text file into a SQL Server Database without manually using SQL DTS?

1 Answers   GE,


what do you understand by change data capture?

0 Answers  


What is trigger and different types of Triggers?

0 Answers   QuestPond,


What is temporal data type?

0 Answers  


we have emp table like Ename,EDOJ,EDOB with Column structure.but we want to know the employee Age.How? Any Body Plz

6 Answers  


What are difference between Cluster index and Non-Cluster index?

0 Answers   QuestPond,


What are sql server procedures?

0 Answers  


Categories