题解|7. 9月各城市每天快车流水数据
9月各城市每天快车流水数据
明确题意:
统计2021年9月各城市的快车流水数据
问题拆解:
- 关联订单表和司机表,得到每个订单中司机的城市ID。知识点:join
- 关联城市表,得到每个司机的城市名。知识点:join
- 筛选订单时间为9月且产品线类型为快车的记录。知识点:where
- 统计各城市的快车流水。知识点:按城市分组group by;统计流水count
- 按示例对结果排序
代码实现:
select city_name, order_info_tb.dt as dt, sum(account)
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