sql学习笔记

1、(CASE WHEN THEN END)用法sql

如何用一句sql获得 age>=10 and age<=20 ; age>20 and age<=80 ; t.age>=90 的三个区间的总量code

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;

结果为blog

相关文章
相关标签/搜索