PostgreSQL按DateTime ASC排序,首先为NULL?我需要按日期/时间字段对PostgreSQL表进行排序。last_updated.但是允许该字段为空或空,我希望记录中包含空。last_updated来以前非零last_updated.这个是可能的吗?order by last_updated asc /* and null last_updated records first ?? */
2 回答
素胚勾勒不出你
TA贡献1827条经验 获得超9个赞
NULLS FIRST | LAST
ORDER BY
... ORDER BY last_updated NULLS FIRST
A 典型DESC
ASC
... ORDER BY last_updated DESC NULLS LAST
CREATE INDEX foo_idx ON tbl (last_updated DESC NULLS LAST);
炎炎设计
TA贡献1808条经验 获得超4个赞
SELECT last_updated FROM your_table ORDER BY CASE WHEN last_updated IS NULL THEN 0 ELSE 1 END, last_updated ASC;
添加回答
举报
0/150
提交
取消