日期:2014-05-18  浏览次数:20409 次

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 desc
select * from goal where bs='b'
union all
select * from #tmp
drop table #tmp

------------------------------------


(10 行受影响)
xh          bs   num
----------- ---- ---------------------------------------
6           b    3000.00
7           b    9000.00
8           b    3000.00
11          b    0.00
19          d    0.00
18          c    0.00
16          c    0.00
11          b    0.00
8           b    3000.00
7           b    9000.00
6           b    3000.00
3           a    3000.00
2           a    9000.00
1           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