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
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 |
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 |
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 |
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 |
Answer / javamaster
select key,count(key) from tablename
group by key order by key
| Is This Answer Correct ? | 0 Yes | 0 No |
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 |
Answer / sagar more
select replace(wm_concat(key||''||'('||count(*)||')' ),',','') key from drop1
group by key
| Is This Answer Correct ? | 0 Yes | 1 No |
What is a transact-sql statement batch in ms sql server?
How to set a database state to offline in ms sql server?
How many databases instances are there in sql server 2000?
How can I check if a view exists in a sql server database?
What are different replication agents and what's their purpose? : sql server replication
Can an entity have two primary keys?
explain what is a schema in sql server 2005? Explain how to create a new schema in a database? : Sql server database administration
What are the parts of a function?
Where sql server usernames and passwords are stored in a sql server?
Why use identity in sql server?
Explain what is “asynchronous” communication in sql server service broker?
How to delete an existing database user?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)