日期:2014-05-16  浏览次数:20885 次

在PostgreSQL中,查询30分钟前的数据的SQL怎样写?时间字段为Time
在PostgreSQL中,查询30分钟前的数据的SQL怎样写?时间字段为Time

------解决方案--------------------


try

SQL code
select * from yourTable where time<now()-05/24

------解决方案--------------------
SQL code

postgres=# \d a
              Table "public.a"
 Column |          Type          | Modifiers 
--------+------------------------+-----------
 id     | integer                | 
 name   | character varying(100) | 
 t_time | time without time zone | 

postgres=# select * from a
postgres-# ;
 id | name  |     t_time      
----+-------+-----------------
  1 | 11111 | 09:35:37.738117
  2 | 22222 | 09:35:37.738117
  3 | 33333 | 09:35:37.738117
    | 34444 | 08:30:20
(4 rows)

Time: 0.297 ms
postgres=# select * from a where current_time - t_time > interval '30 minute';
 id | name  |  t_time  
----+-------+----------
    | 34444 | 08:30:20
(1 row)

Time: 0.519 ms
postgres=#