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

关于排序的问题,高手来看一下吧,谢谢了
比如表table
字段id   ,name,age,city

select   name   from   table  
where   age   in   (20,21,22,23,24)  
or   city   in(   beijing,shanghai,shenzhen)

我如何让age是22排在前面
或者让age是22的又是北京的排在前面

我这现在默认是按id排的

------解决方案--------------------
select name from table
where age in (20,21,22,23,24)
or city in( beijing,shanghai,shenzhen)
order by case when age=22 then -1 else id end
--order by case when age=22 and city= 'beijing ' then -1 else id end

------解决方案--------------------
order by case when age=22 then 1 else 2 end