ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
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.
 Question Submitted By :: Amrita
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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
# 1
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 ?    1 Yes 2 No
Sagun Sawant
 
  Re: 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
# 2
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 ?    0 Yes 0 No
Pradip Jain
 
 
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
How can count the string ? for ex: If i have string like 'bhaskar' then i need like b:1 h:1 a:2 s:1 k:1 r:1 please give any idea on that TCS5
What is excution Plan in sql server TCS1
What is the purpose of using COLLATE in a query?  1
What is a stored procedure?  3
Can you give an example of Stored Procedure?  2
to explain sql server 2000 architecture & authentication  1
What are the all different types of Joins in SQL Server 2000, Anybody can explain each join with definition..Thanks in advance.... Siemens6
What is a job?  3
Can you explain the types of Joins that we can have with Sql Server?  2
PC(code, model, speed, ram, hd, cd, price) Find the hard drive sizes that are equal among two or more PCs. APX2
what is the Surrogate key?and wt is the diff between Primary key and Surrogate Key?  2
if we have a column (Key) in a table. and values of that column is Key 1 1 1 2 2 3 3 4 4 5 5 5 and we want to show the data after query..like.. 1(3) 2(3) 3(2) 4(2) 5(3) how many times a single term comes.. Rolta5
We create an index to fast the search. How it fast the query? Do we write any special keyword with query?  3
WHICH INDEX IS FAST CLUSTER AND NON CLUSTER INDEX L&T2
What all db objects can be found in MSDB database of a SQL Server instance? Accenture1
what is bit data type? and what are the information that can be stored inside a bit column?  2
Which TCP/IP port does SQL Server run on?  2
Which system tables contain information on privileges granted and privileges obtained  1
What is the system function to get the current user's user id? HCL1
can you any body tell me the how to decrease the logfile  4
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com