try: select a1.* from tt a1 inner join (select a.kindsid,a.createDate,count(b.*) as gs from tt a left join tt b on a.a.kindsid=b.kindsid and a.createDate<=b.createDate group by a.kindsid,a.createDate having count(b.*)<=10) c on a1.kindsid=c.kindsid and a1.createDate=c.createDate
1 中央新闻 01 2008-02-02
2 中央新闻 01 2008-02-02
3 中央新闻 01 2008-02-02
4 上海黄浦新闻 02 2008-01-09
4 上海浦东新闻 02 2008-01-09
4 上海长宁新闻 02 2008-01-09
5 广东新闻 03 2009-09-02
select a1.* from tt a1 inner join
(select a.kindsid,a.createDate,count(b.*) as gs from tt a
left join tt b on a.a.kindsid=b.kindsid and a.createDate<=b.createDate
group by a.kindsid,a.createDate having count(b.*)<=10) c
on a1.kindsid=c.kindsid and a1.createDate=c.createDate
http://blog.chinaunix.net/u/29134/showart_465578.html