select 单量区间 , count(distinct 客户id) as 客户数 from ( select 客户id,单量,case when 单量 <= 5 then ‘0-5’ when 单量 >= 6 and 单量 <= 10 then ‘6-10’when 单量 >= 11 and 单量 <= 20 then ‘11-20’else ‘20以上’ end as 单量区间 from ( select 客户id,count(distinct 运单号) as 单量 from 快递揽收表 where 创建日期 >= ‘2020-05-01’ and 创建日期 <= ‘2020-05-31’ group by 客户id) as t1) as t2 group by 单量区间;
在第一节基础上 更新了函数和执行顺序:实操了字符数函数、时间函数、字段截取函数、interval函数等,除最后顺序实操因未导入数据库,导致无法执行