order by case stateid when 2 then 10000 else stateid end desc
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 行受影响)
var result=集合.Select(a=>new{其他字段,stateid=stateid==2?100000:stateid}).OrderByDescending(a=>a.stateid);
改成 order by case stateid when 2 then -10000 else stateid end asc会更好些。
case stateid when 2 then 10000 else stateid end desc
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 行受影响)
var result=集合.Select(a=>new{其他字段,stateid=stateid==2?100000:stateid}).OrderByDescending(a=>a.stateid);
改成
order by
case stateid when 2 then -10000 else stateid end asc会更好些。