题解 | 每天登陆最早的用户的内容喜好 (只有表连接法

 SELECT log_day,user_id,hobby
 FROM  (SELECT user_id, hobby,log_time,first_time, DATE(log_time) AS log_day
    FROM login_tb lt
    LEFT JOIN user_action_tb ut USING(user_id)
    LEFT JOIN  (SELECT MIN(log_time) AS first_time, DATE(log_time) AS log_day
        FROM login_tb l
        LEFT JOIN user_action_tb u USING(user_id)
        GROUP BY log_day) sub ON lt.log_time = sub.first_time
    WHERE first_time IS NOT NULL) sub2
ORDER BY log_day

直接找到每天对应的最早登陆时间,然后用两次左连接即可解决

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务