题解|8. 滴滴2021年9月各城市每天的快车订单量
滴滴2021年9月各城市每天的快车订单量
明确题意:
统计2021年9月各城市每天的快车订单量
问题拆解:
- 关联订单表和司机数据表,得到每个订单中司机的城市ID。知识点:join
- 关联城市表,得到每个司机的城市名
- 筛选9月份的快车订单。知识点:where
- 统计每个城市每天的订单量。知识点:按城市和日期分组group by;对订单数计数count
- 由于司机数据表有重复driver_id,因此需要对统计订单数量时需要去重
代码实现:
select city_name, order_info_tb.dt as dt, count(distinct order_id) as flash_count
from order_info_tb
join driver_tb using(driver_id)
join city_tb using(city_id)
where product_line_id=2 and order_info_tb.dt >= "2021-09-01" and order_info_tb.dt <= "2021-09-30"
group by city_name, dt
order by dt