? 求助高手 超难 sql 语句编写???

cvrli 2008-03-02 09:39:23
高手你好,,
我想写一条,sql 语句 查找30条 ("fs")=1 的记录 ,如果("fs")=1记录不足30条 那么有多少显示多少 ,剩下的用 ("fs")=2 显示 如果还不足,再显视,("fs")=3记录,,
...全文
205 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Bruce828253 2008-03-03
  • 打赏
  • 举报
回复
select top 30 * from table where fs='1' or fs='2' or fs ='3' order by fs
yimeng123 2008-03-03
  • 打赏
  • 举报
回复
重金诚聘C++
http://topic.csdn.net/u/20080227/14/8bce0844-bd15-42f0-9cda-a343d5d6601b.html?seed=2111206245
seemon 2008-03-03
  • 打赏
  • 举报
回复
SELECT * FROM
(SELECT *, ROW_NUMBER() OVER (PARTITION BY fs ORDER BY 任意一个字段) AS NUM FROM TB) T
WHERE NUM>=30 ORDER BY FS,NUM
ojuju10 2008-03-03
  • 打赏
  • 举报
回复

select top 30 * from
(
select top 30 *,'1' as px from tb where fs = 1
union all
select top 30 *,'1' as px from tb where fs = 2
union all
select top 30 *,'1' as px from tb where fs = 3
) t
order by px
山之魂2 2008-03-03
  • 打赏
  • 举报
回复
SELECT TOP 30 * FROM tb where fs> 0 ORDER BY fs
dawugui 2008-03-02
  • 打赏
  • 举报
回复
高手你好,,
我想写一条,sql 语句 查找30条 ("fs")=1 的记录 ,如果("fs")=1记录不足30条 那么有多少显示多少 ,剩下的用 ("fs")=2 显示 如果还不足,再显视,("fs")=3记录,,

--
select top 30 * from
(
select top 30 * from tb where fs = 1
union all
select top 30 * from tb where fs = 2
union all
select top 30 * from tb where fs = 3
) t
cxmcxm 2008-03-02
  • 打赏
  • 举报
回复
只要查询的结果按你的规则排序,再取前30条记录即可
select top 30 fs from 表 where fs>0 order by fs
cvrli 2008-03-02
  • 打赏
  • 举报
回复
("fs")仅一个字段,有三个值,1,2,0
fcuandy 2008-03-02
  • 打赏
  • 举报
回复
SELECT TOP 30 * FROM tb ORDER BY fs
...

34,870

社区成员

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

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