开发者

Postgresql Special Order BY

开发者 https://www.devze.com 2023-01-20 18:15 出处:网络
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 EN

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
0

精彩评论

暂无评论...
验证码 换一张
取 消