开发者

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
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜