有一个category表
cid,cname有一个post表
pid,cid,ptitle请问怎样把post表中,按cid筛选,凡是有cid在category表里面的,每一个cid选出10条记录
用一个select语句实现,谢谢我的是mysql 5.5

解决方案 »

  1.   

    画2个table 出来 ,然后在画出你要的结果 ! 我看看
      

  2.   

    select *
    from post A,category B
    where A.cid=B.cid and 10>=(select count(*) from post C where A.cid=C.cid and A.pid<C.pid)
      

  3.   

    自己找到答案了:
    set @n=0;set @f=0;
    delete from  pre_portal_article_count where aid not in (
    select aid from (select title,@n:=if(@f=catid,@n:=@n+1,1) as id,@f:=catid as catid,aid from pre_portal_article_title order by catid,dateline desc) a where id <10
    )