问题
Using Oracle 11g
I want a single exception to an otherwise sorted table
select fruit as popluar_choices
from menu
order by fruit /* Exception put 'grapefruit' at top of list */
Desired Result
popular_choices
-----------
grapefruit
apple
fig
kiwi
lemon
pear
It's similar to this post: How to apply non standard SQL column sort order?
回答1:
select fruit as popluar_choices
from menu
order by case fruit when 'grapefruit' then 0
else 1
end,
fruit
回答2:
SELECT fruit AS popular_choices FROM menu
ORDER BY
CASE fruit
WHEN 'grapefruit' THEN ''
ELSE fruit
END
回答3:
select fruit as popluar_choices
from menu
order by CASE fruit = 'grapefruit' THEN '__' ELSE fruit END
来源:https://stackoverflow.com/questions/9284536/sql-exception-to-an-otherwise-sorted-result-set