时间范围之间的Postgresql查询

时间范围之间的Postgresql查询,sql,postgresql,Sql,Postgresql,假设我有一个包含以下数据的表格 id shifttime name -----+-----------------------+--------------------- 1 | 18:50:00+05:30 | a 这里我想根据时间范围获取行,这里的问题是,如果结束范围超过24小时,我无法获取行。有人能帮我解答这个问题吗 SELECT * FROM TABLE WHERE shifttime>='17:20:00+05

假设我有一个包含以下数据的表格

id          shifttime              name
-----+-----------------------+---------------------
  1  |   18:50:00+05:30    |     a
这里我想根据时间范围获取行,这里的问题是,如果结束范围超过24小时,我无法获取行。有人能帮我解答这个问题吗

SELECT * FROM TABLE WHERE shifttime>='17:20:00+05:30' AND shifttime<='01:20:00+05:30'


从shifttime>='17:20:00+05:30'和shifttime的表格中选择*,您可以按如下方式进行比较:

where (:start < :end and shifttime >= :start AND shifttime <= :end) or
      (:end < :start and not (shifttime >= :start AND shifttime <= :end) )

在哪里(:start<:end and shifttime>=:start and shifttime=:start and shifttime=:上面的设计很糟糕。如果没有日期组件,你就不知道shifttime在哪里。你也不知道比较时间定位在哪里。将其转换为时间戳并消除不确定性。我做了一些变通,以实现同样的效果。
where(:start<:end and shifttime>=:start and shifttime=:start and shifttime=:'00:00:00+05:30'和shifttime@ranjithkotian…)这应该是不必要的,尽管时区偏移可能会有一些偏差。