【问题标题】:How do you select a date range in postgres?你如何在 postgres 中选择日期范围?
【发布时间】:2012-06-08 02:00:05
【问题描述】:

我在 postgres 数据库中有一个时间戳字段。我想选择上个月内发生的所有日期。所以像 select * from table where timestamp > (current timestamp - 1 month) 之类的。

【问题讨论】:

    标签: sql postgresql date select timestamp


    【解决方案1】:
    select * from table where timestamp > now() - interval '1 month'
    

    【讨论】:

    • (如果这是 Rails,请将 timestamp 替换为 created_at
    【解决方案2】:

    准确地说:

    SELECT *
    FROM   tbl
    WHERE  ts_col >  now() - interval '1 month'
    AND    ts_col <= now();
    

    【讨论】:

      猜你喜欢
      • 2012-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-26
      • 2018-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多