比如表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