sql - 如何在 PostgreSQL 中对整数和文本的组合进行排序?

标签 sql postgresql

我有这张 table

id  value 
1   OK
2   xminimum
3   NO
4   YES

我想按 value 对这个表进行排序,其中 minimum 始终排在第一位,然后根据 value 列的字母顺序排序其余部分

含义:

xminimum
NO
OK
YES

我写了这个查询:

Select *
from table_a
order by case when value='xminimum' then 1 else ????? end

我不知道在 else 中放什么...从概念上讲它应该是 else value end 所以它意味着字母顺序..但我不能将整数与文本结合起来。

我该如何解决?

最佳答案

根据要求,从我的评论中复制:

Select *
from table_a
order by case when value='xminimum' then 1 else 2 end, value

关于sql - 如何在 PostgreSQL 中对整数和文本的组合进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41587450/

相关文章:

sql - Postgis 几何 where 条件

java - RESTful 服务的时间戳精度问题

sql - sp_whoisactive 导致未知查询 : "Insert Into <table_name> select *,%%bmk%% from <table_name> option (maxdop 1)"

php - MySQL SELECT COUNT 返回 NULL

php - CakePHP 3.x : Query to exclude records in which a field can be either NULL or empty ('' )

sql - 获取从星期二到星期一的一周中的数量总和

java - HQL 或 Criteria 中的 CASE 语句

mysql - 大型数据集映射到表中

postgresql - 什么是 PostgreSQL 函数,我什么时候必须使用它们?

macos - Postgres createdb : command not found Mac OS Terminal