求一sql

萧华璋 2007-12-21 01:41:10
实现这个:
从每个栏目中选出两条图片新闻,8条别的新闻,sql该怎样写.
...全文
81 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
萧华璋 2007-12-21
  • 打赏
  • 举报
回复
谢谢.
wzy_love_sly 2007-12-21
  • 打赏
  • 举报
回复
哈哈,未卜先知啊
pt1314917 2007-12-21
  • 打赏
  • 举报
回复

:)
wzy_love_sly 2007-12-21
  • 打赏
  • 举报
回复
5楼和你的表结构一样,改
cloudfang 2007-12-21
  • 打赏
  • 举报
回复
JF
pt1314917 2007-12-21
  • 打赏
  • 举报
回复

select * from 信息表 a where infoId in (select top 2 infoId from 信息表 where sortId=a.sortId and isnull(picture,'')!='' order by infoId desc )--为图片时
union
select * from 信息表 a where infoId in (select top 8 infoId from 信息表 where sortId=a.sortId and isnull(picture,'')='' order by infoId desc )--非图片

wzy_love_sly 2007-12-21
  • 打赏
  • 举报
回复
漫步好仔细啊 呵呵
萧华璋 2007-12-21
  • 打赏
  • 举报
回复
我的表结构是
信息表:
infoId
sortId
infoTitle
picture
pt1314917 2007-12-21
  • 打赏
  • 举报
回复

搞错:
select * from 表名 a where id in (select top 2 id from 表名 where 栏目=a.栏目 and 图片=1 order by id)--为图片时
union
select * from 表名 a where id in (select top 8 id from 表名 where 栏目=a.栏目 and 图片!=1 order by id)--非图片


pt1314917 2007-12-21
  • 打赏
  • 举报
回复
还要是每个栏目都取。1楼似乎掉了
pt1314917 2007-12-21
  • 打赏
  • 举报
回复

select * from 表名 a where exists(select top 2 * from 表名 where 栏目=a.栏目 and 图片=1)--为图片时
union
select * from 表名 a where exists(select top 8 * from 表名 where 栏目=a.栏目 and 图片!=1)--非图片
awfer1 2007-12-21
  • 打赏
  • 举报
回复
ls正解
wzy_love_sly 2007-12-21
  • 打赏
  • 举报
回复
select * from table where id in(select top 2 * from table whre type='图片' ordery by newid())
union
select * from table where id in(select top 8 * from table whre type='别的' ordery by newid())
通过慢sql分析的学习,了解什么是慢sql,以及慢SQL会引起那些性能问题。清楚慢sql日志的设置,然后再通过慢sql分析工具的学习,清楚慢sql分析的步骤和流程。慢sql分析工具:mysqldumpslow工具、explain工具、profile工具、Optimizer Trace工具。 提供课程中所使用的sql语句。 课程内容:第一章:课程简介1、课程介绍2、课程大纲 第二章:慢sql简介1、慢sql简介2、慢sql会引起的问题 第三章:慢日志的设置1、慢sql的分析流程2、慢日志参数理解3、慢日志参数设置:第1种方式:my.ini文件设置4、慢日志参数设置:第2种方式:sql脚本设置5、慢日志参数设置-效果验证 第四章:如何发现慢sql1、如何发现慢sql:第1种方式:慢日志文件2、如何发现慢sql:第2种方式:mysql库的slow_log表 第五章:慢sql分析工具1、慢sql提取-mysqldumpslow工具-使用方法2、慢sql提取-mysqldumpslow工具-操作实战3、慢sql的执行计划分析-explain分析-执行计划结果说明4、慢sql的执行计划分析-explain分析-索引介绍+type类型举例5、慢sql的资源开销分析-profile分析-分析步骤6、慢sql的资源开销分析-profile分析-show profile执行阶段说明7、慢sql的资源开销分析-profile分析-完整列表说明+操作实战8、慢sql的跟踪分析-Optimizer Trace分析-分析步骤9、慢sql的跟踪分析-Optimizer Trace表的介绍10、索引失效场景举例 第六章:慢日志清理1、慢日志清理

34,591

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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