从今天开始不熬夜

2022-09-09   阅读量: 484

Mysql 数据分析师

SQL德邦面试题

扫码加入数据分析学习群

image.png

如图所示,按照要求用SQL查询:

select * from 揽收表;

select 单量,count(*) as 客户数

from

(select

客户id,

count(distinct 运单号) as 下单次数,

case when count(distinct 运单号)<=5 then '0-5'

when count(distinct 运单号)<=10 then '6-10'

when count(distinct 运单号)<=20 then '11-20'

else '20以上'

end as 单量

from 揽收表

where month(创建日期)=5

group by 客户id) as t

group by 单量;

#先按照给定的区间,将去重的运单号划分到其中,之后再对区间分组求和,用case when 逻辑更清晰,用if判断也可


添加CDA认证专家【维克多阿涛】,微信号:【cdashijiazhuang】,提供数据分析指导及CDA考试秘籍。已助千人通过CDA数字化人才认证。欢迎交流,共同成长!
23.5688 1 0 关注作者 收藏

评论(0)


暂无数据

推荐课程

推荐帖子