MySQL 取分类后的前n条

select *
from (SELECT @num:=0,@AAA:= 0) temp join
(
   select 
   @num := if(@AAA = AAA, @num + 1, 1) as row_number,
   @AAA := AAA as Dummy,
   mt.* 
  from table1 mt 
  where Created_Time BETWEEN DATE_SUB(CURRENT_TIMESTAMP,INTERVAL 1 DAY) and CURRENT_TIMESTAMP 
  order by AAA, ID desc
) as x where x.row_number <= 3;
原文地址:https://www.cnblogs.com/krisy/p/2956092.html