日期:2014-05-17  浏览次数:20561 次

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' --上面不小心多了个符号。