(
select a.complain_person,a.accept_id,(case when b.degree>='5' then '满意' else '' end) as score1,(case when b.degree<'5' then '不满意' else '' end) as score2
from CS_ACCEPT_MAIN a,CS_ACCEPT_CALLBACK_RESULTS b
where a.accept_id=b.acceptid
)
select '合计','000' as accept_id,sum(case when score1='满意' then 1 else 0 end) || '',sum(case when score2='不满意' then 1 else 0 end) || ''
from temp
with temp as
(
select a.complain_person,a.accept_id,(case when b.degree>='5' then '满意' else '' end) as score1,(case when b.degree<'5' then '不满意' else '' end) as score2
from CS_ACCEPT_MAIN a,CS_ACCEPT_CALLBACK_RESULTS b
where a.accept_id=b.acceptid
)
select complain_person,accept_id,score1,score2
from temp
order by accept_id
with temp as
(
select a.complain_person,a.accept_id,(case when b.degree>='5' then '满意' else '' end) as score1,(case when b.degree<'5' then '不满意' else '' end) as score2
from CS_ACCEPT_MAIN a,CS_ACCEPT_CALLBACK_RESULTS b
where a.accept_id=b.acceptid
)
select '合计','000' as accept_id,sum(case when score1='满意' then 1 else 0 end) || '',sum(case when score2='不满意' then 1 else 0 end) || ''
from temp
UNION ALL --union all相当于叠加s
select complain_person,accept_id,score1,score2
from temp
order by accept_id
union all相当于对表结果的叠加。聚合函数对可以划分出多列