造了点数据,不知道是这个意思不
create table test
(total int,
ssbm varchar2(20));
insert into test values (5,'02(5)');
insert into test values (5,'02(5)');
insert into test values (5,'04(5)');
insert into test values (5,'04(5)');
insert into test values (5,'03(5)');
commit;
查询:
select ssbm||'('||cnt||')' from (select substr(ssbm,1,instr(ssbm,'(')-1) ssbm,count(*) cnt from test group by substr(ssbm,1,instr(ssbm,'(')-1)) t
结果:
select T.total, (A.ssbm || '(' || to_char(A.cnt_ssbm) || ')') as ssbm, T.id from T,(select substr(ssbm,1,2) as ssbm, count(ssbm) as cnt_ssbm from T group by substr(ssbm,1,2)) A where A.ssbm = substr(T.ssbm,1,2);
这样写再试一下。