排名

用户解题统计

过去一年提交了

勋章 ①金银铜:在竞赛中获得第一二三名;②好习惯:自然月10天提交;③里程碑:解决1/2/5/10/20/50/100/200题;④每周打卡挑战:完成每周5题,每年1月1日清零。

收藏

收藏日期 题目名称 解决状态
2025-08-21 滴滴面试真题(4)未完成订单在第二天继续呼叫的比例  未解决
2025-08-21 滴滴面试真题(3)UTC转化后的本地时间呼叫高峰期  已解决
2025-08-05 从未被领取的优惠券  已解决
2025-08-05 全量用户标签表  已解决
2025-08-05 计算每天的有效订单完成率  已解决
2025-08-05 计算每个城市的有效订单完成率  未解决
2025-08-05 只买iPhone的用户  已解决
2025-08-05 播放量最高的标签  未解决
2025-08-05 超过3个标签的视频  已解决
2025-08-04 计算视频的平均观看完成率  已解决
2025-08-04 深圳气温异常年份  已解决
2025-08-04 德州扑克起手牌-同花两高张  已解决
2025-08-04 好友步数排名-考虑反向好友关系  已解决
2025-08-04 好友步数排名-不考虑反向好友关系  已解决
2025-08-04 7月之后再也没活跃过的用户  已解决
2025-08-04 窗口函数(4)越来越喜欢召妓,窗口函数用累计(2)  未解决
2025-08-04 小结(2)越花越多是死罪,按月统计Substr  已解决
2025-08-04 小结(1)大数据早就能扫黄,找足证据不慌张  已解决
2025-08-04 经过第四象限的所有函数  未解决
2025-08-04 查询播放量为0的歌手及其专辑  已解决
2025-08-01 通勤、午休、临睡个时间段活跃人数分布  已解决
2025-08-01 上月活跃用户数  已解决
2025-08-01 滴滴面试真题(2)打车订单呼叫应答时间  已解决
2025-08-01 抖音面试真题(1)T+1日留存率  已解决
2025-08-01 餐厅的客单价增长趋势  已解决
2025-08-01 每日新增用户  已解决
2025-08-01 得物面试真题(4)首单Mac二单iPhone的客户  已解决
2025-08-01 快手面试真题(3)同时在线人数峰值时点  未解决
2025-08-01 快手面试真题(2)同时在线人数峰值  未解决
2025-07-31 基于共同兴趣爱好的餐厅推荐(6)-好基友(5)  已解决
2025-07-31 基于共同兴趣爱好的餐厅推荐(4)-好基友(2)  已解决
2025-07-31 海王:1小时发3个红包  未解决
2025-07-31 统计各省红包金额的总金额、平均数、中位数、众数、标准差以及75分位数  未解决
2025-07-31 红包金额中位数  已解决
2025-07-31 从商品角度统计收藏到购买的转化率  已解决
2025-07-31 给商品打四类标签(列)  已解决
2025-07-31 给商品打四类标签(行)  已解决
2025-07-31 只被收藏未被购买的商品  已解决
2025-07-30 窗口函数(3)越来越喜欢召妓,窗口函数用累计(1)  已解决
2025-07-30 窗口函数(2)所有前一和每类前一,继续搞懂排序窗口函数  已解决
2025-07-30 时间日期(6)爽完来根事后烟,不羡鸳鸯不羡仙  已解决
2025-07-30 时间日期(5)三腿爱往会所走,全当良心喂了狗  已解决
2025-07-30 时间日期(4)阶段综合-按月统计日花费,一天都不要浪费  已解决
2025-07-30 各地区包含“中国”或“中”字开头的公司数量及比例  已解决
2025-07-30 中字头上市企业  已解决
2025-07-30 各行业第一家上市公司  已解决
2025-07-30 销售金额前10的商品信息(2)  已解决
2025-07-30 海王发红包  已解决
2025-07-30 登录天数分布  已解决
2025-07-29 与X轴有且只有一个交点的一元二次函数  已解决
2025-07-29 找出与X轴交点大于0的一元一次函数  已解决
2025-07-29 城市平均最高气温  已解决
2025-07-29 查询所有起点和终点都属于餐饮类别的行程  已解决
2025-07-29 查询所有终点是餐饮类地点的行程记录  已解决
2025-07-29 时间日期(3)按月统计日花费,一天都不要浪费  已解决
2025-07-29 时间日期(2)按月统计日花费,一天都不要浪费  已解决
2025-07-29 时间日期(1)按月统计日花费,一天都不要浪费  已解决
2025-07-29 表连接(1)你们难道都去过?那就试试用InnerJoin  已解决
2025-07-29 子查询(1)玩的最嗨那天在做甚?要用Where子查询  已解决
2025-07-29 字符串与通配符(2)好多关键词做规则,可以使用rlike  已解决
2025-07-29 分类(1)姿势太多很过分,分类要用CaseWhen  已解决
2025-07-29 条件过滤(3)Hour函数很给力,组合条件要仔细  已解决
2025-07-29 各班第一名  已解决
2025-07-29 NULL的知识点  已解决
2025-07-29 平均分最高的班级  已解决
2025-07-29 化学老师的教学成果  已解决
2025-07-29 语文数学英语至少1门超过100分的同学  已解决
2025-07-29 CASE WHEN-男女学生的数量  已解决
2025-07-29 GROUP BY-年龄最大学生的出生日期  已解决
2025-07-29 字符串函数-查找任教5个班级的所有教师  已解决
2025-07-28 数学成绩分段统计(2)  已解决
2025-07-28 优异物理成绩的分布  已解决
2025-07-28 S1年级物理成绩前10名(1)  已解决

评论笔记

评论日期 题目名称 评论内容 站长评论
2025-08-05 全量用户标签表 
with tem as(
select 
i.cust_uid,
i.age,
i.gdr,
case when i.age<25 and i.gdr='F' then 1 else 0 end as young_lady,
count(case when r.if_vw=1 then r.prd_id else null end) as browsed_count,
count(case when r.if_buy=1 then r.prd_id else null end) as buy_count
from tb_cst_bas_inf i
left join tb_pg_act_rcd r on i.cust_uid=r.cust_uid
group by 1,2,3
)
select 
cust_uid,
age,
gdr,
young_lady,
case when browsed_count>=2 then 1 else 0 end as browsed_multiple_products,
case when buy_count>=2 then 1 else 0 end as bought_multiple_products
from tem
order by 1

Note一下写法
啥也没说
2025-08-05 总播放时长最长的视频 
select i.video_id,
i.title,
cast(sum(timestampdiff(second,w.start_time,w.end_time)/3600)as decimal(10,2)) as total_play_duration_hours
from ks_video_inf i
left join ks_video_wat_log w on i.video_id=w.video_id
where date(w.start_time)>adddate(current_date,interval -1 month)
group by 1,2
order by 3 desc
limit 5;

提醒自己:先算second 再换回hour,不要直接用hour
啥也没说
2025-08-04 查找没有观看记录的用户 
select distinct t100.usr_id from bilibili_t100 t100
left join bilibili_t20 t20 on t100.usr_id=t20.usr_id
where t20.usr_id is null
啥也没说
2025-08-04 计算视频的平均观看完成率 
SELECT 
    v.video_id,
    v.title,
    COALESCE(AVG(TIMESTAMPDIFF(SECOND, w.start_time, w.end_time) / v.duration), 0) AS avg_completion_rate
FROM ks_video_inf v
LEFT JOIN ks_video_wat_log w ON v.video_id = w.video_id
GROUP BY v.video_id, v.title
ORDER BY avg_completion_rate DESC;

为什么这道题答案要使用inner join 呢?原题中要求‘如果视频没有被观看过,则显示完成率为0’,如果inner join 不应该就排除掉了没有被观看过的那些视频吗?
啥也没说
2025-08-04 找出最近一周内发布的竖屏视频 
select 
video_id,author_id,title
from ks_video_inf
where current_date-date(release_time)<=7 and screen_type='p'
order by release_time desc;
这个代码为何不能通过?
能通过啊
2025-08-04 深圳气温异常年份 
with t as (
select
year(dt) as year,
cast(avg(replace(tmp_h, '℃', '')) as decimal(10,2)) as avg_tmp_h,
lag(round(avg(tmp_h), 2))over(order by year(dt)) as lastyear_avg_tmp_h
from weather_rcd_china
where year(dt) between 2011 and 2022 and city='shenzhen'
group by 1
)
select year,
avg_tmp_h,
case 
        when lastyear_avg_tmp_h is null then 'No' 
        when abs(avg_tmp_h - lastyear_avg_tmp_h) >= 1 then 'Yes' 
        else 'No' 
    end as significant_change
from t
order by 1
啥也没说
2025-08-04 7月之后再也没活跃过的用户 
with active_users_before_august as (
    select 
        usr_id,
        date_format(login_time, '%Y-%m') as month
    from 
        user_login_log
    where 
        login_time < '2024-08-01'
    group by 
        usr_id, date_format(login_time, '%Y-%m')
    having 
        count(*) >= 10
),
active_users_after_august as (
    select 
        usr_id,
        date_format(login_time, '%Y-%m') as month
    from 
        user_login_log
    where 
        login_time >= '2024-08-01'
    group by 
        usr_id, date_format(login_time, '%Y-%m')
    having 
        count(*) >= 10
)
select 
    count(distinct au1.usr_id) as inactive_user_count
from 
    active_users_before_august au1
left join 
    active_users_after_august au2 
    on au1.usr_id = au2.usr_id
where 
    au2.usr_id is null;
啥也没说
2025-08-04 小结(2)越花越多是死罪,按月统计Substr 
select date_format(trx_time,'%Y-%m') as trx_mon,
count(1) as trx_cnt,
sum(trx_amt) as trx_amt
from cmb_usr_trx_rcd
where 
usr_id = 5201314520 
and date(trx_time) > '2022-11-01' and date(trx_time) <= '2024-12-31'
and ((truncate(trx_amt,0) rlike"88$|98$" and trx_amt>200) and hour(trx_time)  in (0,23,1,2) or upper(mch_nm) rlike "足疗|保健|养生|SPA")
group by 1
order by 1;
注意全角竖线和半角竖线!!!!
啥也没说
2025-08-04 用户听歌习惯的时间分布 
select user_id,
dayname(start_time)as day_of_week,
count(*) as listens_per_day
from listen_rcd
group by 1,2
order by 1,2

参考答案中join用户表的意义在于?
本题的输出结果是一样的,不加也行
2025-08-04 至少两门科目大于等于110分的学生 
select *
from subject_score
where if(chinese>=110,1,0)+if(math>=110,1,0)+if(english>=110,1,0) >=2

with t as(
select 
student_id,chinese,math,english,
case when chinese>=110 then 1 else 0 end as chinese_lag,
case when math>=110 then 1 else 0 end as math_lag,
case when english>=110 then 1 else 0 end as english_lag
from subject_score
)
select student_id,chinese,math,english
from t
where chinese_lag + math_lag + english_lag >= 2
order by 1;
啥也没说
2025-08-01 每个商品的用户性别分布 
select r.prd_id,m.prd_nm,
sum(case when i.gdr='M' then 1 else 0 end) as male_count,
sum(case when i.gdr='F' then 1 else 0 end) as female_count,
sum(case when i.gdr='M' then 1 else 0 end) + sum(case when i.gdr='F' then 1 else 0 end) as total_count
from tb_pg_act_rcd r
left join tb_prd_map m on r.prd_id=m.prd_id
left join tb_cst_bas_inf i on i.cust_uid=r.cust_uid
where r.if_buy=1
group by 1,2
order by r.prd_id
啥也没说
2025-08-01 上月活跃用户数 
SELECT 
    COUNT(DISTINCT usr_id) AS active_users
FROM 
    user_login_log
WHERE 
    login_time >= ADDDATE(DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH), '%Y-%m-01 00:00:00')
    AND login_time < DATE_FORMAT(CURRENT_DATE, '%Y-%m-01 00:00:00');
啥也没说
2025-08-01 滴滴面试真题(2)打车订单呼叫应答时间 
SELECT 
    avg(TIMESTAMPDIFF(SECOND, call_time, grab_time)) AS avg_response_time_seconds
FROM 
    didi_order_rcd
WHERE 
    grab_time != '1970-01-01 00:00:00';
啥也没说
2025-08-01 得物面试真题(1)每周iPhone用户和非iPhone用户 
select date_format(purchase_time,'%Y%u') as week_number,
case when product_type='iPhone' then'iPhone'
     else 'Not iPhone' end as category,
count(distinct user_id) as user_count
from apple_pchs_rcd
group by 1,2
order by 1,2
标记一个 date_format 在周数上的应用
啥也没说
2025-08-01 时间日期(5)三腿爱往会所走,全当良心喂了狗 
select 
'2022-10-03 17:20:20'as time_he_love_me,
datediff(current_date,'2022-10-03')as days_we_falling_love,
timestampdiff(hour,'2022-10-03 17:20:20',current_timestamp)as hours_we_falling_love,
datediff(min(trx_time),'2022-10-03') as days_he_fvck_else
from cmb_usr_trx_rcd
where
 usr_id = '5201314520' and mch_nm ='红玫瑰按摩保健休闲'
group by 
    mch_nm; 
啥也没说
2025-08-01 快手面试真题(2)同时在线人数峰值 
WITH user_events AS (
    SELECT 
        live_id,
        enter_time AS event_time,
        1 AS user_change 
    FROM ks_live_t1
    UNION ALL
    SELECT 
        live_id,
        leave_time AS event_time,
        -1 AS user_change 
    FROM ks_live_t1
),
online_timeline AS (
    SELECT 
        live_id,
        event_time,
        SUM(user_change) OVER (
            PARTITION BY live_id 
            ORDER BY event_time, user_change DESC  
        ) AS current_online
    FROM user_events
)
SELECT 
    o.live_id,
    l.live_nm,
    MAX(o.current_online) AS max_online_users
FROM online_timeline o
LEFT JOIN ks_live_t2 l ON o.live_id = l.live_id
GROUP BY o.live_id, l.live_nm, l.live_type
ORDER BY max_online_users DESC;

为什么无法通过呢?
 MAX(o.current_online) AS max_online_users 这里也要分组取最大
2025-08-01 分类别人均在线时长最火直播间 
with t1 as(
select t1.live_id,t2.live_nm,t2.live_type,
sum(timestampdiff(second,t1.enter_time,t1.leave_time)) as total_duration,
count(distinct t1.usr_id) as total_users,
sum(timestampdiff(second,t1.enter_time,t1.leave_time)) /count(distinct t1.usr_id) as avg_duration
from ks_live_t1 t1
left join ks_live_t2 t2 on t1.live_id=t2.live_id
where t1.enter_time between '2021-09-12 23:00:00' and '2021-09-13 03:59:59' 
group by 1,2,3
order by 1
),
t2 as (
select live_id,live_nm,live_type,total_duration,total_users,avg_duration,
row_number()over(partition by live_type order by avg_duration desc) as ranking
from t1
)
SELECT live_id,live_nm,live_type,total_duration,total_users,avg_duration
FROM t2 
WHERE ranking = 1
ORDER BY live_id;
啥也没说
2025-07-31 基于共同兴趣爱好的餐厅推荐(3)-好基友(1) 
select r.cust_uid,r1.cust_uid as cust_uid_1,r.mch_nm 
from mt_trx_rcd1 r
left join mt_trx_rcd1 r1 on r.mch_nm=r1.mch_nm 
where r.cust_uid='MT10000' and r.mch_nm='兰州李晓明拉面馆' and r.cust_uid!=r1.cust_uid
group by 1,2
order by 2
啥也没说
2025-07-31 比较男女收发红包的差异 
select i.gdr,
 count(distinct r.snd_usr_id) as sender_count,
 count(*) as total_send_count,
 count(distinct r.rcv_usr_id) as total_distinct_receiver_count,
 round(sum(r.pkt_amt)/count(distinct r.snd_usr_id),2) as avg_amount,
 round((sum(case when r.rcv_datetime!='1900-01-01 00:00:00' then 1 else 0 end)/count(*))*100,2) as receive_rate
 from tx_red_pkt_rcd r 
 left join tx_usr_bas_info i on r.snd_usr_id=i.usr_id
 where date(r.snd_datetime)='2021-02-13' and i.gdr is not null
 group by 1;

这里的发送给多少人不应该是 所有人数去重吗?参考答案的意思似乎是如果有多人同时给一个人发送,那么被发送的那个人可以计算多次?
你的理解是正确的。 已修改答案。
恭喜你彻底搞清楚了 count(1)\count(distinct )
2025-07-31 从商品角度统计收藏到购买的转化率 
with t1 as(
select fav.mch_id, count(distinct cust_uid) as fav_user_count
from xhs_fav_rcd fav
group by mch_id
),
t2 as(
select fav.mch_id,
count(distinct fav.cust_uid)as conv_user_count
from xhs_fav_rcd fav
left join xhs_pchs_rcd pch on fav.mch_id=pch.mch_id and fav.cust_uid=pch.cust_uid and fav.fav_tm<pch.pchs_tm
where pch.mch_id is not null
group by 1     
)

select t1.mch_id,t1.fav_user_count,
COALESCE(t2.conv_user_count, 0) as conv_user_count ,
COALESCE(ROUND((cast(t2.conv_user_count as float) / t1.fav_user_count)*100,2), 0) as conversion_rate
from t1
left join t2 on t1.mch_id=t2.mch_id
order by 4 desc
注意最后要处理小数点的问题
啥也没说
2025-07-30 时间日期(5)三腿爱往会所走,全当良心喂了狗 
select 
'2022-10-03 17:20:20'as time_he_love_me,
datediff(current_date,'2022-10-03')as days_we_falling_love,
timestampdiff(hour,'2022-10-03',current_timestamp)as hours_we_falling_love,
datediff(min(trx_time),'2022-10-03') as days_he_fvck_else
from cmb_usr_trx_rcd
where
 usr_id = '5201314520' and mch_nm ='红玫瑰按摩保健休闲'
group by 
    mch_nm;
这为什么过不了呢
timestampdiff(hour,'2022-10-03',current_timestamp)as hours_we_falling_love,被减数要精确到小时。
蝶衣说过,说好的一辈子,少一天、一小时都不算。
2025-07-30 2020年后上市的医药公司 
select
year(list_date) as Y,
count(distinct ts_code)as cnt
from stock_info
where year(list_date) between 2021 and 2024 and name rlike '.*(医|药|生物).*'
group by 1
order by 1
答案包括2020年的,错了吧
已调整。
2025-07-30 各行业第一家上市公司 
select ts_code,symbol,name,area,industry,list_date from
(
select 
*,
row_number()over(partition by industry order by list_date) as ranking
from stock_info
)t
where t.ranking=1
order by t.list_date;
为什么这个代码无法通过呢?
1、数据纰漏。有些股票的industry为空,你的可以找出来,正确答案是非空的
2、统计下你找出答案的行数,和正确答案找出的行数,看是谁多了或者谁少了
2025-07-29 条件过滤(3)Hour函数很给力,组合条件要仔细 
这个答案为何无法通过?
select *
from cmb_usr_trx_rcd
where usr_id=5201314520 and date(trx_time) between '2024-09-01' and '2024-09-30' and (format(trx_time,'%H-%i-%s') >='22:00:00' or format(trx_time,'%H-%i-%s')<='05:00:00' )
order by trx_time

原答案中的hour(trx_time) between 0 and 5 会包含05:59:59 不符合题意吧?
1、5点多的,只要不超过6点,都应被算进去;
2、你的代码细节有问题,详见下面
select *
from cmb_usr_trx_rcd
where usr_id=5201314520 and date(trx_time) between '2024-09-01' and '2024-09-30' and (date_format(trx_time,'%H:%i:%s') >='22:00:00' or date_format(trx_time,'%H:%i:%s')<='06:00:00' )
order by trx_time
2025-07-29 小结-从不缺考的学生 
select student_id
from scores
group by student_id
having sum(case when score is null then 1 else 0 end)=0 
order by student_id
手动点赞。你跟下面的米斯兰迪同学, 都是好样的,学以致用,举一反三!
2025-07-28 S1年级物理成绩前10名(1) 
WITH ranked_scores AS (
  SELECT 
    s.student_id,
    s.name,
    sc.score,
    ROW_NUMBER() OVER (ORDER BY sc.score DESC) AS rnk
  FROM students s
  JOIN scores sc ON s.student_id = sc.student_id
  WHERE s.grade_code = 'S1' AND sc.subject = '物理'
)
SELECT student_id, name, score, rnk
FROM ranked_scores
WHERE rnk <= 10
ORDER BY rnk,student_id
为什么不加入 PARTITION BY s.grade_code 代码会显示错误呢?理论上where先执行,然后再执行窗口函数,where后就已经得到了S1的物理成绩了,按理说,加与不加得到的结果应该是一致的呀?
1、跟你说的执行顺序无关;
2、评论区里所有人的问题都指向一类错误:排序字段未枚举全的时候,排名具有随机性。你看下你的答案,物理满分的同学有5个,黄志强、吴勇、柯玉珍、李秀云、赵龙。网站列出的正确答案,也是这5个人,只是名次不同。
3、理解了排名的随机性,本题就算学到了。

提交记录

提交日期 题目名称 提交代码
2025-08-21 滴滴面试真题(3)UTC转化后的本地时间呼叫高峰期 
select hour(local_call_time) as local_hour, count(order_id) as cnt
from 
(
    select
        order_id,
        cust_uid,
        adddate(call_time, INTERVAL -3 HOUR) as local_call_time
    from 
        didi_order_rcd
)t
group by hour(local_call_time) 
order by 2 desc
2025-08-21 滴滴面试真题(3)UTC转化后的本地时间呼叫高峰期 
select hour(local_call_time) as local_hour, count(order_id) as cnt
from 
(
    select
        order_id,
        cust_uid,
        adddate(call_time, INTERVAL -4 HOUR) as local_call_time
    from 
        didi_order_rcd
)t
group by hour(local_call_time) 
order by 2 desc
2025-08-21 滴滴面试真题(1)-打车订单应答率 
select count(order_id) as total_orders,
sum(case when grab_time !='1970-01-01 00:00:00' then 1 end) as answered_orders,
concat(round((sum(case when grab_time !='1970-01-01 00:00:00' then 1 end)/count(order_id))*100,2),'%') as answer_rate
from didi_order_rcd 
where date(call_time)='2021-05-03'
2025-08-21 各行业第一家上市公司 
select ts_code,symbol,name,area,industry,list_date
from(
select *,
row_number()over(partition by industry order by list_date) as ranking
from stock_info
)t
where ranking =1 and industry is not null
order by list_date
2025-08-05 找出最受欢迎的促销活动 
select
p.event_id,
count(distinct p.product_id) as product_count
from promotion_events e 
left join promotion_products p on e.event_id=p.event_id
group by 1
limit 1;
2025-08-05 从未被领取的优惠券 
select distinct c.* 
from coupons c
left join user_coupons u on c.coupon_id=u.coupon_id
where u.user_id is null 
order by 1
2025-08-05 从未被领取的优惠券 
select * from coupons c
left join user_coupons u on c.coupon_id=u.coupon_id
where u.user_id is null 
order by 1
2025-08-05 统计每个用户领取了多少张优惠券 
select 
user_id,
count(*) as coupon_count
from user_coupons
group by 1
order by 2 desc;
2025-08-05 统计每个用户领取了多少张优惠券 
select 
user_id,
count(distinct user_id) as coupon_count
from user_coupons
group by 1
order by 2 desc;
2025-08-05 使用了全场通用优惠券的订单数量 
select
count(distinct order_id) as order_count
from order_promotions o
left join coupons c on o.coupon_id=c.coupon_id
where coupon_type='全场通用'
2025-08-05 查询所有正在进行中的促销活动 
select * 
from promotion_events
where is_active=1 and date(start_time)<='2025-03-08' and date(end_time)>='2025-03-08'
order by 1;
2025-08-05 全量用户标签表 
with tem as(
select 
i.cust_uid,
i.age,
i.gdr,
case when i.age<25 and i.gdr='F' then 1 else 0 end as young_lady,
count(case when r.if_vw=1 then r.prd_id else null end) as browsed_count,
count(case when r.if_buy=1 then r.prd_id else null end) as buy_count
from tb_cst_bas_inf i
left join tb_pg_act_rcd r on i.cust_uid=r.cust_uid
group by 1,2,3
)
select 
cust_uid,
age,
gdr,
young_lady,
case when browsed_count>=2 then 1 else 0 end as browsed_multiple_products,
case when buy_count>=2 then 1 else 0 end as bought_multiple_products
from tem
order by 1
2025-08-05 统计每个城市各状态的单量(行转列) 
select
cty,
sum(case when status='completed' then 1 else 0 end) ascompleted_orders,	
sum(case when status='cancel_by_usr' then 1 else 0 end) ascancelled_by_usr_orders,	
sum(case when status='cancel_by_driver' then 1 else 0 end) ascancelled_by_driver_orders
from hll_t1
group by 1
order by 1
2025-08-05 统计每个城市各状态的单量 
select cty,
status,
count(*) as order_count
from hll_t1
group by 1,2
order by 1,2
2025-08-05 找出北京和柳州单量最多的司机 
select 
cty,
driver_id,
order_count
from (
select
cty,
driver_id,
count(*) as order_count,
row_number()over(partition by cty order by count(*) desc) as ranking
from hll_t1
where cty in('北京','柳州')
group by 1,2
)t
where ranking =1
2025-08-05 计算车方和司机被禁止的比率 
select 
role,
count(distinct usr_id) as total_count,
count(distinct case when banned=1 then usr_id else null end) as banned_count,
concat(cast(count(distinct case when banned=1 then usr_id else null end)/count(distinct usr_id)*100 as decimal(10,2)),'%') as banned_rate
from hll_t2
group by 1
2025-08-05 计算每天的有效订单完成率 
select order_dt
, count(distinct order_id) 
,count(distinct case when status='completed' and b.banned=0 and c.banned=0  then order_id else null end) 
,(count(distinct case when status='completed' and b.banned=0 and c.banned=0  then order_id else null end) /count(distinct order_id) )
from hll_t1 a 
inner join hll_t2 b 
on a.usr_id=b.usr_id
inner join hll_t2 c 
on a.driver_id=c.usr_id
group by order_dt
2025-08-05 计算每个城市的有效订单完成率 
with t as(
select 
cty,
count(*) as valid_order_count
from hll_t1 t1
left join hll_t2 t2 on t1.usr_id=t2.usr_id
left join hll_t2 t3 on t1.driver_id=t3.usr_id
where t2.banned=0 and t3.banned=0 and status='completed'
group by t1.cty
)
select 
hll_t1.cty,
count(*) as total_order_count,
valid_order_count,
concat(cast((valid_order_count/count(*)*100) as decimal(10,2)),'%')as completion_rate
from hll_t1
left join t on hll_t1.cty=t.cty
group by 1,3
order by 4 desc;
2025-08-05 按天粒度统计订单明细 
select
date_format(start_time,'%Y-%m-%d') as dt,
start_loc,
end_loc,
count(*) as cnt,
count(distinct user_id) as usr_cnt,
count(*)/count(distinct user_id) as cnt_per_usr
from hello_bike_riding_rcd
where date_format(start_time,'%Y-%m')='2024-10'
group by 1,2,3
order by 1,2,3
2025-08-05 行程细分到小时 
select 
Hour(start_time) as H,
start_loc,
end_loc,
count(*) as cnt
from hello_bike_riding_rcd
where ((start_loc='方恒购物中心'and end_loc='望京南') or (start_loc='望京南'and end_loc='方恒购物中心')) and user_id='u802844' 
group by 1,2,3
order by 1,2