1、条件求和
例: 统计A类型总分数,B、C总分数,年龄大于15的总分
select
sum(case when t.type in ('A') then t.score else 0 end) wgtzb,
sum(case when t.type in ('B','C') then t.score else 0 end) wgthb,
sum(case when t.age > 15 then t.score else 0 end) thick40
from stu t
2、显示百分比
用decode判断,如果有 .52% 的结果,显示为 0.52%
select
decode(TRUNC(m.wgt / m.weight * 100),
0,
replace(round((m.wgt / m.weight) * 100, 2), '.', '0.'),
round((m.wgt/ m.weight) * 100, 2)) || '%'
from xxtable m