第1个回答 推荐于2016-09-27
select 'A' P1,a.P2
from (select count(1) P2 from t where t.t2 like '%A%' ) a
union all
select 'B',b.P2
from (select count(1) P2 from t where t.t2 like '%A%' ) b
.....本回答被提问者采纳
第2个回答 2012-05-14
select id=identity(int,1,1)
into #a from dbo.syscolumns a, dbo.syscolumns b
select substring(a.t2,b.id,charindex(',',a.t2+',',b.id)-b.id),count(a.t1)
from tablet a,#a b
where b.id<=len(a.t2)
and substring(','+a.t2,b.id,1)=','
group by substring(a.t2,b.id,charindex(',',a.t2+',',b.id)-b.id)
第3个回答 2012-05-14
select B.A,count(*) total from A,B where A.A like '%'+B.A+'%' group by B.A
下面是赠送的:
select chr(ascii('A') + level - 1) from dual connect by rownum <= 26
如果看不懂或你还搞不定就留下言
第4个回答 2012-05-14
select 'A',a.P2
from (select count(1) P2 from t where t.t2 like '%A%' ) a
union
select 'B',b.P2
from (select count(1) P2 from t where t.t2 like '%B%' ) b
union
..........
最好调用存储过程