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

How to create and drop temp table in sql server?

0 Answers  


What is clustered index

0 Answers  


what are candidate key, alternate key and composite key? : Sql server database administration

0 Answers  


Explain external key management in sql server 2008

0 Answers  


Mention the uses of stored procedures.

0 Answers  






how can u select the Distinct values in the table, table having 20 columns , i want all columns

2 Answers  


What types of integrity are enforced by a foreign-key constraint

1 Answers  


What are actions, how many types of actions are there, explain with example? : sql server analysis services, ssas

0 Answers  


Is it possible to allow NULL values in foreign key? I s it possible to use different constraints for the same column in the table (i.e) (id int NOT NULL,UNIQUEUE)

1 Answers  


please bar with my english i having a database called tblhallreservation in which res_date is date field has to select all the fields in table deponding on month either has to display all details for the month jan or feb and so on

1 Answers  


What is analysis service repository?

0 Answers  


How real and float literal values are rounded?

0 Answers  


Categories