如何在一个表里,按分类,每个分类select10条数据?

CTBOK 2013-07-23 11:57:58
有一个category表
cid,cname

有一个post表
pid,cid,ptitle

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

我的是mysql 5.5
...全文
161 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
keatkeat1987 2013-07-24
  • 打赏
  • 举报
回复
画2个table 出来 ,然后在画出你要的结果 ! 我看看
CTBOK 2013-07-24
  • 打赏
  • 举报
回复
自己找到答案了: 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 )
CTBOK 2013-07-24
  • 打赏
  • 举报
回复
这个语句不能用啊
rucypli 2013-07-24
  • 打赏
  • 举报
回复
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)

56,678

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧