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 / krishna reddy l

select convert(varchar(5),ex)+'('+convert(varchar(5),count
(ex))+')' from example group by ex
Table name example and columna name ex

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 / rajkumar v

select SNo, '(' + convert(varchar,count(SNo)) + ')' from
test group by SNo having COUNT(*)>=1

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 / madhu sudhan g

Hiiiii

Lets the table name is No1 having column A is of int data Type
Now the query is
select convert(nvarchar(5),A) + '(' +
convert(nvarchar(5),count(1))+')' from NO1 GROUP BY A

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 / rajkumar.v

select convert(varchar,id) + '(' + CONVERT(varchar,count
(id)) + ')' as tot from tblname group by id

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

select key,count(key) from tablename
group by key order by key

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 / praveen singh

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 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 / sagar more

select replace(wm_concat(key||''||'('||count(*)||')' ),',','') key from drop1
group by key

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More SQL Server Interview Questions

What does asynchronous call backs means?

0 Answers   Alcatel-Lucent,


DIFFERENCE BETWEEN SQL SERVER 2005 and 2008

2 Answers   ADP,


How to view existing indexes on an given table using sp_help?

0 Answers  


What is a filestream?

0 Answers  


What is the difference between executequery () and executeupdate ()?

0 Answers  






What is ms sql server index?

0 Answers  


What is it unwise to create wide clustered index keys?

0 Answers  


What are the 10 characteristics of data quality?

0 Answers  


List the different types of collation sensitivities in sql server?

0 Answers  


Write the SQL query to drop, truncate and delete table.

0 Answers   HPCL, Hughes Systique Corporation, Ittiam Systems,


How to write character string constants or literals in ms sql server?

0 Answers  


What happens if the update subquery returns no rows in ms sql server?

0 Answers  


Categories