2022-09-09
阅读量:
725
SQL德邦面试题
如图所示,按照要求用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判断也可






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
1条评论