step1:使用driver_id相等条件,将order_info_tb左连接driver_tb;

step2:使用city_id相等条件,左连接city_tb;

step3:限制条件为类型是快车、日期为2021年9月;

step4:按照city_id、日期分组统计每天的流水数据;

step5:按城市编号、时间排序。

SELECT city_name, a.dt, sum(account) as journal_account

FROM order_info_tb a

LEFT JOIN driver_tb b

ON a.driver_id=b.driver_id

LEFT JOIN city_tb c

on b.city_id=c.city_id

WHERE product_line_id=2 and DATE_FORMAT(a.dt, '%Y-%m')='2021-09'

GROUP BY b.city_id, a.dt

ORDER BY b.city_id, a.dt;