项目里面有遇到一个需求,查询一个表,先group by ,再按group 的count(*)进行倒序,取出每个group里面发表时间最新的一个纪录,之前的同事SQL是这样写的 SELECT * FROM ( SELECT * FROM table WHERE id = ? AND status = ? ORDER BY created_time DESC ) AS a GROUP BY a.group ORDER BY count(*) DESC LIMIT 但是呢,最后取出来的数据是乱序的,也…