how to show this table value from below output can u send coding.
id field
1 x
2 x
3 x
4 y
5 y
6 z
------------------
output
3x
2y
1z
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
manuel josephPosted Jul 17, 2012, 4:28 AM
Sudhakar ChaudharyPosted Jul 14, 2012, 11:50 AM
create database demo
use demo
create table tabs(id int,chr char(1))
insert into tabs values('1','x')
insert into tabs values('2','x')
insert into tabs values('3','x')
insert into tabs values('4','y')
insert into tabs values('5','y')
insert into tabs values('6','z')
select * from tabs
select (cast(count(chr) as char)+chr) as result from tabs group by chr
output
result
------------
3x
2y
1z
Vilas GitePosted Jul 14, 2012, 10:13 AM
Follow Santosh Kumar query... perfect
for more details about cast-convert in sql.
http://msdn.microsoft.com/en-us/library/ms187928.aspx
Santhosh Kumar JayaramanPosted Jul 14, 2012, 8:18 AM
Here is my sample demo
create table test(
id int,
valued varchar(2))
insert into test values(1,'x')
insert into test values(2,'x')
insert into test values(3,'x')
insert into test values(4,'y')
select Cast(COUNT(1) as varchar)+ valued from test group by valued:
output-
3x,
1y