2022-09-09
閱讀量:
762
SQL德邦面試題
如圖所示,按照要求用SQL查詢:
select * from 攬收表;
select 單量,count(*) as 客戶數(shù)
from
(select
客戶id,
count(distinct 運(yùn)單號) as 下單次數(shù),
case when count(distinct 運(yùn)單號)<=5 then '0-5'
when count(distinct 運(yùn)單號)<=10 then '6-10'
when count(distinct 運(yùn)單號)<=20 then '11-20'
else '20以上'
end as 單量
from 攬收表
where month(創(chuàng)建日期)=5
group by 客戶id) as t
group by 單量;
#先按照給定的區(qū)間,將去重的運(yùn)單號劃分到其中,之后再對區(qū)間分組求和,用case when 邏輯更清晰,用if判斷也可






評論(0)


暫無數(shù)據(jù)
推薦帖子
0條評論
0條評論
0條評論