窗口函数解法 SELECT b.name,c.name,a.date FROM ( select *, row_number() over (partition by user_id order by date desc) as rn FROM login ) AS a LEFT JOIN user b ON a.user_id = b.id LEFT JOIN client c ON a.client_id = c.id WHERE rn = 1 order by b.name