【问题标题】:finding total values for each month in postgres在 postgres 中查找每个月的总值
【发布时间】:2023-03-17 22:39:02
【问题描述】:

我需要找到一年中每个月的“wentto”旅行总数。假设 2010 年的所有月份都在数据集中表示。

【问题讨论】:

    标签: sql database postgresql dataset


    【解决方案1】:

    您可以使用条件聚合:

    select date_trunc('month', date) as tt,
           count(*) filter (where event = 'wentto')
    from t
    where date >= '2010-01-01' and date < '2011-01-01'
    group by tt
    order by tt;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-01
      • 2018-12-19
      • 1970-01-01
      相关资源
      最近更新 更多