select CLASS_ID
,count(1) as 'titlenum'
,sum(case when TITLE='A' then 1 else 0 end) as 'Anum'
,sum(case when TITLE='B' then 1 else 0 end) as 'Bnum'
from A
group by CLASS_ID
order by CLASS_ID
select class_ID,
count(title) as titlenum,
(select count(title) from 表A as a where a.class_ID =表A.class_ID and title='A') as Anum,
(select count(title) from 表A as a where a.class_ID =表A.class_ID and title='B') as Bnum
from 表A
group by class_ID
select class_ID,(select count(title) from 表A where class_ID=a.class_ID),(select count(title) from 表A where title='A' and class_ID=a.class_ID),
(select count(title) from 表A where title='B' and class_ID=a.class_ID) from 表A a group by class_ID