不列出表结构及测试数据,只能这样大概写个思路了:select a.from (select t1.*,(select count(*)+1 from 表 where 分组字段=t1.分组字段 and 排序字段
mysql分组后,取每组的前3条数据并且有顺序
不列出表结构及测试数据,只能这样大概写个思路了:
select a.*
from
(
select t1.*,(select count(*)+1 from 表 where 分组字段=t1.分组字段 and 排序字段<t1.排序字段) as group_id
from 表 t1
) a
where a.group_id<=32010-08-06
select *
from tb k
where 3>(select count(*) from tb where k.分组字段=分组字段 and 你的排序字段>k.你的排序字段)2010-08-06