一、(CASE WHEN THEN END)用法
如何用一句sql得到 age>=10 and age<=20 ; age>20 and age<=80 ; t.age>=90 的三个区间的总量
select
sum(case when t.age>=10 and t.age<=20 then 1 else 0 end) a,
sum(case when t.age>20 and t.age<=80 then 1 else 0 end) b,
sum(case when t.age>=90 then 1 else 0 end) c
from test t;
结果为