Mysql分组后取前十条数据

select a.*
from table a
where 10 > (select count(*) from table b where b.dif_distance = a.dif_distance and b.id > a.id ) 
order by a.id
-- 按照dif_distance分组, 取前10条,"b.id > a.id" 表示取按照id取最后的十条

 

posted @ 2022-06-13 10:54  远启  阅读(2615)  评论(0编辑  收藏  举报