题解|9. 9月各城市每天的司机数
9月各城市每天的司机数
明确题意:
统计9月份各城市每天的司机数
问题拆解:
- 关联司机的城市名。知识点:join
- 筛选9月活跃的司机记录。知识点:where
- 统计各城市每天的司机数。知识点:按城市和日期分组group by;统计司机数量count
- 根据示例数据,按城市名倒序
代码实现:
select city_name, dt, count(distinct driver_id) as driver_num
from driver_tb
join city_tb using(city_id)
where dt >= "2021-09-01" and dt <= "2021-09-30"
group by city_name, dt
order by city_name desc