step1:按driver_id分组,限制查找在线总时长大于2消失的driver_id和在线总时长;

step2:按driver_id相等的条件左连接 driver_tb;

step3:按city_id相等条件左连接city_tb;

step4:查找相关信息。

SELECT c.city_name, a.driver_id, a.online_sum

FROM

(SELECT driver_id, SUM(online_len) as online_sum

FROM online_time_tb

GROUP BY driver_id

HAVING SUM(online_len)>2) 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;