一个无限分类表、
一个新闻表

解决方案 »

  1.   

    参考下贴中的多种方法http://topic.csdn.net/u/20091231/16/2f268740-391e-40f2-a15e-f243b2c925ab.html
    [征集]分组取最大N条记录方法征集,及散分....
      

  2.   

    分类表
    id  name fid
    1    中国    0
    2    北京    1
    3    上海    1
    4    广州    1新闻表
    id title  cid
    1  新闻1  2
    2  新闻2  2
    3  新闻3  3
    4  新闻4  3
    5  新闻5  4
    6  新闻6  4
    7  新闻7  2
    8  新闻8  3简单写了一下、想查询出结果:
    想取出一个大分类下(如:中国)的每个小分类(有多少算多少)的前2条新闻记录
      

  3.   

    select b.*
    from 分类表 a inner join 新闻表 b on a.id=b.cid
    where a.fid=1
    and 2>(select count(*) from 新闻表 where cid=b.cid and id<b.id)
      

  4.   


    新闻表的cid = 分类表的id
      

  5.   

    假设新闻表ID唯一
    select * from 分类表 c inner join (
    select a.id,a.title,a.cid from 新闻表 a inner join 新闻表 b
    on a.cid=cid and a.id<=b.id group by a.id,a.title,a.cid having count(b.id)<=2)
    on a.cid=c.id
      

  6.   

    刚才ACMAIN_CHM的sql有个问题
    就是 一但新闻表的里面的 条数大于3的话则、那个分类就不显现
      

  7.   

    刚才ACMAIN_CHM的sql有个问题
    就是 一但新闻表的里面的小分类条数大于3的话则、那个小分类就不显现