我想在 sql 语句的 ORDER BY 后面,再加上一个条件,怎么办?

gxbhhp 2003-05-14 11:52:01
比如:

select * from table1 order by money -- 加上一个条件,比如:where duan=1

那样的,效果和:


select * from table1 where duan=1 order by money 一样的。

意思就是,order by 必须 在条件 where 之前,有什么办法解决吗?
...全文
2378 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
caiyunxia 2003-05-14
  • 打赏
  • 举报
回复
select * from table1 order by case when duan=1 then money else money+100 end
select * from table1 order by isnull(money , -1000000)
宸瑜 2003-05-14
  • 打赏
  • 举报
回复
尽量缩小检索范围,或建立索引
宸瑜 2003-05-14
  • 打赏
  • 举报
回复
你可以在order by 语句中利用条件语句啊,用case 或 IIF()函数
gxbhhp 2003-05-14
  • 打赏
  • 举报
回复
firetoucher(蹈火者) 的得搜索两次,有些烦和影响速度,还有更简单的办法吗?
firetoucher 2003-05-14
  • 打赏
  • 举报
回复
select * from
(select * from table1 orderby money) a
where a.duan = 1
caiyunxia 2003-05-14
  • 打赏
  • 举报
回复
不行
ODER BY CASE 。。。。

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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