mysql 分组内获取最新一条数据 GROUP_CONCAT

SELECT `user_id`
    , SUBSTRING_INDEX(GROUP_CONCAT(ip ORDER BY id DESC), ',', 1) AS ip
FROM `visit_log`
GROUP BY `user_id`
LIMIT 100

GROUP_CONCAT

可以组内进行排序

SUBSTRING_INDEX

获取第一个逗号左侧的值

此处评论已关闭