[英]postgresql order by open and closing date
我的桌子看起来像这样:
eventname varchar(255)
open int unixtimestamp
close int unixtimestamp
我想按最快的顺序对表进行排序,这意味着它的即将发生的事件(打开和关闭<now())PostgreSQL应该按打开的顺序对表进行排序,但是如果它是当前或过去的事件(关闭> now()),则应该通过关闭命令表
我尝试使用以下order by子句将其归档:
ORDER BY case when close>1423053440 and open>1423053440 then 'open desc' else 'close desc' END
基本上是行不通的,因为刨床不支持按个案排序的asc / desc装饰
任何提示高度赞赏
最好的祝福
安德烈亚斯
使用多个键:
ORDER BY (case when close > 1423053440 and open > 1423053440 then 1 else 2 end),
(case when close > 1423053440 and open > 1423053440 then open end) desc,
close asc;
第一个表达式将打开位置放在第一位。 第二个命令open
的降序。 第三个命令使用close
排序其余的命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.