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                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
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
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..
 Question Submitted By :: Sandy
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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..
Answer
# 1
select top 10 cast(key as varchar)
+ '(' + cast(count(key) as varchar) + ')' 
from TableName
group by key


Hanamesh Havale
Influx Infotech
 
Is This Answer Correct ?    3 Yes 1 No
Hanamesh Havale
 
  Re: 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..
Answer
# 2
Take a example as to find the same student who got first and
second marks in each of sub.

SELECT RollNo,COUNT(Rank) FROM Student GROUP BY RollNo,rank
ORDER BY rank
 
Is This Answer Correct ?    1 Yes 1 No
Hitesh Kumar Vyas S
 
 
 
  Re: 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..
Answer
# 3
Select cast(idKey as varchar)+'('+cast(count(idKey) as 
varchar)+')' 
from #tbl1 group by idKey
 
Is This Answer Correct ?    2 Yes 1 No
Saravanan P
 
  Re: 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..
Answer
# 4
create table #temp1(id int) 

insert into #temp1 values(4)


declare @str nvarchar(500)
select @str=''
select @str =@str+ id  from (select  cast(id as varchar) +'('+
cast(count(id) as varchar(22))+ ')'  id  from #temp1  group
by id) t
select @str


output will be :1(5)2(1)3(2)4(1)
 
Is This Answer Correct ?    0 Yes 0 No
Praveen Singh
 
  Re: 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..
Answer
# 5
select  convert(varchar,key) + '('+ convert(varchar,
count(key))+')' from table_name group by key

Hanamesh, why top 20?
 
Is This Answer Correct ?    1 Yes 0 No
Pradip Jain
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
explain different types of jions with examples briefly? Zensar1
What is the difference between constraints and triggers? Wipro6
How to write stored procedure to update the data in 10 tables  4
can we call stored Procedure in Function in Sql Server 2000 and vice versa. eSoft2
How to Display, Amount of Disk Activity Generated by Transact-SQL Statements?  1
1.can we set the more than 1 primary keys for a table? 2.please give me the difference between Cluster Index and non-Clustered Index 3.can we use query like this "Select * from Table1,Table2;"  6
Hi Friends, I have a table in which there are thousands of records and in city field there is NULL value for all records now i want to change that null value with distinct values in each record say delhi, bihar, agra, jaipur etc, what will be the query for that????? its not possible to update thousands of records one by one. is there any alternative ...? Plz help ... its urgent Thanx in advance  1
When do you create cluster and noncluster index? Satyam4
Which system tables contain information on privileges granted and privileges obtained  1
Write an SQL query if u want to select the data from one block which intern reflects in another block ? thanx,do reply Covansys1
What is Query Execution Plan? How does it help optimize or tune a database driven application? Accenture2
What are the new features in SQL Server 2005? Emphasis2
What is Peer to peer Replication? HCL1
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
Can you give an example of Stored Procedure?  2
In performance wise distinct is good or group by is good? eg:select name from emp group by name; select distinct name from emp; Infosys4
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.  2
What is difference beteen Migration and Upgrdation? Satyam4
What r sql reporting services and analysis services? how can we use it. Microsoft2
hi, may i know what is the command to get abstract the current month, current year and current day from a given date.i want these three in a isolated way..seperatedly is that any way in sql server 2000  3
 
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