一张表有多个类别的新闻,希望每个类别新闻取最新10条 Atable; id,topic,kindsid,createDate

解决方案 »

  1.   

    id,topic,     kindsid,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
      

  2.   

    正确结果是kindsid=01,02,03,.....每个类别取日期最近的10条记录
      

  3.   

    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
      

  4.   

    To get what you want,just visit here.
    http://blog.chinaunix.net/u/29134/showart_465578.html