sql语句如何 按指定的某列的摸个值排序

wftznexwn 2013-04-10 04:12:11
如题:

select * from dbo.Archives_CM where cmcode='3707850101000009' order by HumanCode='03'
按HumanCode='03'的那一列排序
...全文
1386 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dengixnyu 2013-04-10
  • 打赏
  • 举报
回复
select * from dbo.Archives_CM where cmcode='3707850101000009' and HumanCode='03' union all select * from dbo.Archives_CM where cmcode='3707850101000009' and HumanCode<>'03' --上面不小心多了个符号。
dengixnyu 2013-04-10
  • 打赏
  • 举报
回复
select * from dbo.Archives_CM where cmcode='3707850101000009' and HumanCode='03' union all select * from dbo.Archives_CM where cmcode='3707850101000009' and HumanCode=<>'03'
MrYangkang 2013-04-10
  • 打赏
  • 举报
回复
HumanCode='03' 排序 首先 HumanCode<>'03' 的数据要不要,如果要,只能这样写 select * from dbo.Archives_CM where cmcode='3707850101000009' order by HumanCode desc[asc] 如果不要,那就这样写 select * from dbo.Archives_CM where cmcode='3707850101000009' and HumanCode='03' order by HumanCode desc[asc] 也就是说,不能按照某列的值排序,只能按照表中的某列排序,而不是值
hyrongg 2013-04-10
  • 打赏
  • 举报
回复
如果HumanCode 固定只有那么几个,可以用Case


select * from dbo.Archives_CM where cmcode='3707850101000009'  
order by case when HumanCode='03' then 1
                   else 2 end asc
wftznexwn 2013-04-10
  • 打赏
  • 举报
回复
把这个放在首位
wftznexwn 2013-04-10
  • 打赏
  • 举报
回复
HumanCode='03' 这一行
水族杰纶 2013-04-10
  • 打赏
  • 举报
回复
HumanCode='03' 值是什么?

22,209

社区成员

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

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