读书人

sql语句怎么 按指定的某列的摸个值排序

发布时间: 2013-04-12 18:33:12 作者: rapoo

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

select * from dbo.Archives_CM where cmcode='3707850101000009' order by HumanCode='03'
按HumanCode='03'的那一列排序
[解决办法]
如果HumanCode 固定只有那么几个,可以用Case



select * from dbo.Archives_CM where cmcode='3707850101000009'
order by case when HumanCode='03' then 1
else 2 end asc

[解决办法]
select * from dbo.Archives_CM where cmcode='3707850101000009' and HumanCode='03'
union all
select * from dbo.Archives_CM where cmcode='3707850101000009' and HumanCode=<>'03'
[解决办法]
select * from dbo.Archives_CM where cmcode='3707850101000009' and HumanCode='03'
union all
select * from dbo.Archives_CM where cmcode='3707850101000009' and HumanCode<>'03' --上面不小心多了个符号。

读书人网 >SQL Server

热点推荐