【问题标题】:Postgresql select distinct for every unique quarterPostgresql 为每个独特的季度选择不同的
【发布时间】:2021-01-08 16:43:10
【问题描述】:

我有一个问题

select * from table_name where sales=0

我从中得到了以下数据

现在,每个季度我想选择不同的行,这样最终数据就会像这样

能够通过

获取各个季度的数据
select distinct quarter, id from some_view where quarter='2020-Q2'

但我无法获得可以容纳所有季度数据的单个查询。

请建议如何进行

【问题讨论】:

    标签: sql postgresql select distinct where-clause


    【解决方案1】:

    我可能过于简单化了......但你似乎确实想要:

    select distinct quarter, id from some_view where sales = 0
    

    这将为您提供所有不同的 querter/id 元组,满足 where 子句的行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-05
      • 2018-05-13
      • 2012-07-28
      • 2021-08-15
      • 2013-12-28
      • 1970-01-01
      • 2012-11-08
      相关资源
      最近更新 更多