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

相關文章
相關標籤/搜索