Postgresql Special Order BY
I need to use an ORDER BY
on a table but keep some special rows on top.
The rows that have name='de开发者_开发百科veloper'
for example.
ORDER BY CASE WHEN name = 'developer' THEN '0' ELSE name END
You could also do the ORDER BY without the usage of a CASE:
ORDER BY
name = 'developer' DESC,
name ASC;
Something like this might work for you.
SELECT * FROM table ORDER BY CASE WHEN name = 'developer' THEN 0 ELSE 1 END, name
精彩评论