【问题标题】:Query accounts pending for exactly 2 days - SQL查询帐户等待正好 2 天 - SQL
【发布时间】:2021-11-25 14:00:06
【问题描述】:

我正在尝试查询已等待批准整整两 (2) 天的帐户。 “created_at”列是没有时区的时间戳。我面临的问题是我不知道如何过滤两天前的“created_at”列。这是我目前所拥有的:

SELECT *
FROM kyc_document_check
WHRE status = 'pending'
AND created_at = 

而且我不知道在created_at = 后面放什么才能恰好在两天前完成。

我正在使用带有 pgAdmin-4 的 PostgreSQL 数据库

【问题讨论】:

  • 这将取决于您的“created_at”日期格式,但请尝试查找从日期中减去天数。您可能需要做类似的事情。

标签: sql postgresql datetime filtering


【解决方案1】:

如果 created_at 是 date,则使用:

where created_at = current_date - 2;

如果是timestamp,由于时间部分,最好使用范围条件:

where created_at >= current_date - 2
  and created_at < current_date - 1;

【讨论】:

    【解决方案2】:

    试试这个:

    SELECT *
    FROM kyc_document_check
    WHERE status = 'pending' AND = age(created_at, current_timestamp()) = '2 days'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-16
      • 2010-10-30
      • 1970-01-01
      • 1970-01-01
      • 2017-08-09
      • 2014-07-14
      相关资源
      最近更新 更多