MySQL 8可以使用如下方法来分组查询并返回每组最新数据
WITH ranked_records AS ( SELECT m.*, ROW_NUMBER() OVER (PARTITION BY chapter_id ORDER BY created_date DESC) AS rn FROM learn_record AS m Where user_id=#{param1} ) SELECT * FROM ranked_records WHERE rn = 1;