mysql分组查询取每组前N条

请大神支招:怎样用分组查询得到每组前4条数,(注:数据量较大,不能使用子查询)

select * from (
select row_number() over(partition by ancester分组列 order by productid排序列) as a,* from Products
) as p where a<4前4个

给你一个取各组前5条数据的例子吧,可以参考一下

 select *  
  from (select t.*,  
               (Row_number() over(partition by 分组字段 order by 排序字段)) rn  
          from 表名字 t)  
 where rn < 6;  

http://blog.csdn.net/zhichao2001/article/details/6068893 这可以参考下 其他的也无能为力了

分组之后按理来说每一组的数据要么是唯一的要么就是一样的数据,你要怎么查前4条?,除非是你分组的字段以外还有字段,那么怎么可能不用子查询

首先分组分别获取总数,然后包裹一层,分别取前四个。

实在不行,在后台代码做,操作未必都要用mysql语句去解决

select * from table group by id order by id desc

select * from(
select * from xxx group by

limit 0,4

select top 4 * from table group by id

select you need character from the table group by "" limit0,4

select top 4 列名 from 表名l group by 列名

select (@i:=@i+1)i, id, operator, startDate _ledge_form a,(select @i:=0) t2 where submit_type=1 order by a.orderId asc 实现排序功能