相信大家对一列的不同值做统计都很熟悉了,例如:
select sum(decode(sex, '男', 1, 0)) 男, sum(decode(sex, '女', 1, 0)) 女
from test;
那么要对一列的值做范围内的统计,又该怎么做呢?
select sum(decode(greatest(age, 60), least(age, 100), 1, 0)) "年龄60-100",
sum(decode(greatest(age, 30), least(age, 59), 1, 0)) "年龄30-59",
sum(decode(greatest(age, 0), least(age, 29), 1, 0)) "年龄0-29"
from test;
|