题解 | #店铺订单分析#
店铺订单分析
https://www.nowcoder.com/practice/232f0717822a483c990c4d0e52a98faf
与上一题差不多,就是需求有些绕,其实求发一样,单量都给了,进行判断在分组求 方法一:if方法 select t.订单数区间, count(客户编码) as "人数" from( select 客户编码, if(订单数 between 0 and 2,"0-2",if(订单数 between 3 and 5 ,"3-5","5单以上")) as "订单数区间" from 订单表 ) as t group by t.订单数区间 order by t.订单数区间 方法二:case when then end select t.订单数区间, count(客户编码) as "人数" from( select 客户编码, case when 订单数 between 0 and 2 then "0-2" when 订单数 between 3 and 5 then "3-5" when 订单数>5 then "5单以上" end as "订单数区间" from 订单表 ) as t group by t.订单数区间 order by 订单数区间