按距“现在”的绝对距离对时间戳(包括将来)进行排序。 [英] Sort timestamps (including future) by absolute distance from "now"
本文介绍了按距“现在”的绝对距离对时间戳(包括将来)进行排序。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用日期
字段,我可以此:
ORDER BY ABS(expiry - CURRENT_DATE)
具有 timestamp
字段时,出现以下错误:
With a timestamp
field I get the following error:
函数abs(interval)不存在
function abs(interval) does not exist
推荐答案
给出正确的排序):
ABS(EXTRACT(DAY FROM expiry - CURRENT_TIMESTAMP))
不幸的是,正如欧文·布兰德斯特(Erwin Brandstetter)指出的那样,它将排序的粒度减小到一整天。
Unfortunately, as Erwin Brandstetter pointed out, it reduces the granularity of the sorting to a full day.
这篇关于按距“现在”的绝对距离对时间戳(包括将来)进行排序。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文