mysql 实现分组取出各自组内排序前三的数据时间:2024-03-12 11:06:40 利用变量实现 set @c_id:=null, @rownum:=0;select*from(SELECT t.*,@rownum:= (case when @c_id = t.c_id then @rownum + 1 else 1 end) count,@c_id:=t.c_idFROM t_class_message t order by t.c_id asc, t.create_time desc ) Twhere count < 4 ;