sql排序。。。
有个字段stateid 值为1、2、3、4、5
我想让查询出来的数据让值等2排在最前面。其它的按ID降序,有没有办法。。。。
[解决办法]
order by case stateid when 2 then 10000 else stateid end desc
[解决办法]
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 行受影响)
[解决办法]
var result=集合.Select(a=>new{其他字段,stateid=stateid==2?100000:stateid}).OrderByDescending(a=>a.stateid);
[解决办法]