首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2013-04-12 
sql语句如何 按指定的某列的摸个值排序如题:select * from dbo.Archives_CM where cmcode37078501010000

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

热点排行