step1:按driver_id相等的条件,将order_info_tb左连接driver_tb;
step2:按city_id相等的条件,左连接ciity_tb;
step3:按driver_id分组,统计不重复的订单数量;
step4:只显示订单量大于1的司机信息。
select city_name, driver_id, COUNT(DISTINCT order_id) as order_num
FROM(
SELECT a.driver_id, city_name, order_id 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)t
GROUP BY driver_id
HAVING order_num>1
ORDER BY driver_id;