【问题标题】:postgresql count all entries created on a particular date?postgresql 计算在特定日期创建的所有条目?
【发布时间】:2020-12-07 20:16:09
【问题描述】:

我想计算在 postgresql 中特定日期创建的所有条目。该表有一个 created_date 字段,类型为 time stamp without time zone , created_date 中的条目之一看起来像这样 2020-08-18 12:26:22.641。

select count(*) from table where created_date='2020-08-18*' 这是我尝试的,但不起作用。

我如何计算这种情况下是否存在包含或正则表达式匹配的内容? 谢谢!!

【问题讨论】:

标签: sql postgresql


【解决方案1】:

最有效的方法是使用范围条件:

select count(*)
from the_table
where created_date >= date '2020-08-18'
  and created_date < date '2020-08-19';

另一种选择是将时间戳转换为 date 值:

select count(*)
from the_table
where created_date::date = date '2020-08-18'

【讨论】:

    猜你喜欢
    • 2022-12-09
    • 1970-01-01
    • 2015-01-10
    • 2014-01-27
    • 1970-01-01
    • 2021-08-08
    • 2019-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多