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

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

step3:按照driver_id分组,统计不重复的乘客数;

step4:只显示乘客数大于1的相关信息;

step5:按司机编号排序。

select driver_id, COUNT(DISTINCT passenger_id) as passenger_num, city_name

FROM(

SELECT a.driver_id, city_name, passenger_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 passenger_num>1

ORDER BY driver_id;