case when ... end + count 的用法

select 
count(case when from_unixtime(time/1000,'%Y-%m-%d') between '2018-01-01' and '2018-02-01' then 1 end) 一月份,
count(case when from_unixtime(time/1000,'%Y-%m-%d') between '2018-02-01' and '2018-03-01' then 1 end) 二月份,
count(case when from_unixtime(time/1000,'%Y-%m-%d') between '2018-03-01' and '2018-04-01' then 1 end) 三月份,
count(case when from_unixtime(time/1000,'%Y-%m-%d') between '2018-04-01' and '2018-05-01' then 1 end) 四月份,
count(case when from_unixtime(time/1000,'%Y-%m-%d') between '2018-05-01' and '2018-06-01' then 1 end) 五月份,
count(case when from_unixtime(time/1000,'%Y-%m-%d') between '2018-06-01' and '2018-07-01' then 1 end) 六月份,
count(case when from_unixtime(time/1000,'%Y-%m-%d') between '2018-07-01' and '2018-08-01' then 1 end) 七月份,
count(case when from_unixtime(time/1000,'%Y-%m-%d') between '2018-08-01' and '2018-09-01' then 1 end) 八月份
from table_name;

你可能感兴趣的:(case when ... end + count 的用法)