题解 | #牛客的课程订单分析(七)#
牛客每个人最近的登录日期(二)
http://www.nowcoder.com/practice/7cc3c814329546e89e71bb45c805c9ad
SELECT u.name AS u_n,c.name AS c_n, a.date FROM (SELECT user_id,client_id,date FROM login WHERE (user_id,date) IN (SELECT user_id,MAX(date) FROM login GROUP BY user_id) ) a LEFT JOIN user u ON a.user_id = u.id LEFT JOIN client c ON c.id = a.client_id ORDER BY u.name
差点就被折磨得要死,直接取出最大值和 user_id,但是group by后 因为多合一,这个client就不知道怎么选了,因为有多个,所以会出错,然后这里面弄了个判断,还是错,因为两个条件where判断 我没加() 谨记!!!!!