MySQL拆表遇到的问题:相同用户的多条数据分布在拆前后的多个表中,需要类似GROUP BY的筛选效果~
发布网友
发布时间:2022-05-10 18:40
我来回答
共1个回答
热心网友
时间:2023-10-22 09:07
SELECT MAX(login_time) AS login_time,user_id
FROM(
SELECT MAX(login_time) AS login_time,user_id FROM user_login_record GROUP BY user_id
UNION
SELECT MAX(login_time) AS login_time,user_id FROM user_login_record_20170101 GROUP BY user_id
UNION
SELECT MAX(login_time) AS login_time,user_id FROM user_login_record_20180101 GROUP BY user_id
)TMP GROUP BY user_id