社区
MySQL
帖子详情
如何在一个表里,按分类,每个分类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
打赏
收藏
如何在一个表里,按分类,每个分类select10条数据?
有一个category表 cid,cname 有一个post表 pid,cid,ptitle 请问怎样把post表中,按cid筛选,凡是有cid在category表里面的,每一个cid选出10条记录 用一个select语句实现,谢谢 我的是mysql 5.5
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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)
SQL学习笔记[7] - 怎样在
一个
表里
筛选出每
一个
对象的时间最新的一
条
记录
怎样在
一个
表里
筛选出
每个
对象的时间最新的一
条
记录
oracle 11.2 查询
一个
表里
的某个字段在另外
一个
表里
是否有
数据
item_guid,第二个表 TB_IST_UPLOAD_FILE(附件表) 有字段 relation_guid(取值于第
一个
表的refer_item_guid),本SQL语句查询第
一个
表的每
一个
保养项是否有视频附件存在于第二个
表里
:
select
it.*,ff.file_...
mysql查询
每个
表里
数据
条
数_mysql中查看
数据
库中所有表的记录数
如果使用mysql的版本在5.0及以上,可以通过查询information_schema库中的tables表来获取,该表中使用table_rows记录表的行数信息。例如查看库testdb中所有表的记录数:代码如下复制代码use information_schema;...
同
一个
表中查询
每个
分类
的前5
条
数据
select
a.Id,a.Type,a.Title,a.ShowTime,a.UserName,a.ExternalLinks,a.Cover,a.PlainText, a.IsState,count(*) as num from (
select
* from news where IsState=1 and IsDeleted=0) as a inner join (
select
* ...
sql 获取查询
分类
后第一
条
数据
需求:需要得到按name
分类
,按time排序后的,每一类的第一
条
数据
原始
数据
: 运行sql语句:
select
* from test as tmp where not exists(
select
1 from test where name=tmp.name and time>tmp.time) ...
MySQL
56,678
社区成员
56,708
社区内容
发帖
与我相关
我的任务
MySQL
MySQL相关内容讨论专区
复制链接
扫一扫
分享
社区描述
MySQL相关内容讨论专区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章