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..

Answers were Sorted based on User's Feedback



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..

Answer / hitesh kumar vyas s

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 ?    6 Yes 1 No

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..

Answer / vikas kant

select key,count(key1) from [table_name]
group by key

Is This Answer Correct ?    3 Yes 0 No

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..

Answer / hanamesh havale

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 ?    4 Yes 2 No

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..

Answer / saravanan p

Select cast(idKey as varchar)+'('+cast(count(idKey) as
varchar)+')'
from #tbl1 group by idKey

Is This Answer Correct ?    3 Yes 2 No

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..

Answer / pradip jain

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

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..

Answer / neeraj

If the column name is key
select key,count(*) from jojo
group by key

simple

Is This Answer Correct ?    2 Yes 1 No

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..

Answer / devraj

Table Str:- create table T
( COL1 NUMBER(2));

Data:- select * from t;
col1
1
1
1
2
2
3
3
4
4
5
5
5
Query:-
Select col1 || '(' || Count(col1) || ')' From t Group By
col1;

Is This Answer Correct ?    1 Yes 0 No

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..

Answer / rakesh prasad

In Sql server 2005

select col + '('+ cast (count(col)as varchar(1000))+')'from
tablename group by col

Is This Answer Correct ?    0 Yes 0 No

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..

Answer / guest

3

Is This Answer Correct ?    0 Yes 0 No

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..

Answer / manju

select key,count(key)as"count of items" from tablename
group by key order by key

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

What is a system database and what is a user database?

0 Answers  


How to create an index on a view?

0 Answers  


What is SQL Profiler what is the use of it?

2 Answers   247Customer, Steria,


wht is normalization?can u explain me in detail?

9 Answers   TCS,


What is the syntax for encrypting a column in SQL Server?

0 Answers   MindCracker,






Tell me can we use custom code in ssrs?

0 Answers  


What is unique key constraint?

0 Answers  


what is the Enterprise manager(2000) and management studio (2005)?

2 Answers  


do you know what is a deadlock and what is a live lock? How will you go about resolving deadlocks? : Sql server database administration

0 Answers  


What is Query Execution Plan? How does it help optimize or tune a database driven application?

2 Answers   Accenture, Polaris,


What is the library index called?

0 Answers  


What are primary keys and foreign keys?

3 Answers  


Categories