求一sql

萧华璋 2007-12-21 01:41:10
实现这个:
从每个栏目中选出两条图片新闻,8条别的新闻,sql该怎样写.
...全文
87 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用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())

34,837

社区成员

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

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