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

sql排序。该如何解决

2012-05-08 
sql排序。。。有个字段stateid 值为1、2、3、4、5我想让查询出来的数据让值等2排在最前面。其它的按ID降序,有没有

sql排序。。。
有个字段stateid 值为1、2、3、4、5
我想让查询出来的数据让值等2排在最前面。其它的按ID降序,有没有办法。。。。

[解决办法]

SQL code
order by case stateid when 2 then 10000 else stateid end desc
[解决办法]
SQL code
select * into #tmp from goal where bs<>'2' order by xh descselect * from goal where bs='b'union allselect * from #tmpdrop table #tmp------------------------------------(10 行受影响)xh          bs   num----------- ---- ---------------------------------------6           b    3000.007           b    9000.008           b    3000.0011          b    0.0019          d    0.0018          c    0.0016          c    0.0011          b    0.008           b    3000.007           b    9000.006           b    3000.003           a    3000.002           a    9000.001           a    3000.00(14 行受影响)
[解决办法]
C# code
var result=集合.Select(a=>new{其他字段,stateid=stateid==2?100000:stateid}).OrderByDescending(a=>a.stateid);
[解决办法]
探讨
SQL code

order by
case stateid when 2 then 10000 else stateid end desc

热点排行