【问题标题】:Grouping data for one row对一行数据进行分组
【发布时间】:2021-10-20 21:58:40
【问题描述】:

我在数据库中有一个如下所示的数据:

我需要它看起来像这样:

查询应该是什么样的?所以基本上我总是需要动作的最大日期,并且只为每个属性显示一行。我正在使用 SQL 开发人员。感谢您的帮助!

【问题讨论】:

    标签: sql oracle group-by pivot grouping


    【解决方案1】:

    您可以使用条件案例表达式和聚合。

    select Attribute, 
        Max(case when action='produced' then date end) as Produced_Date,
        Max(case when action='sold' then date end) as Sold_Date
    from t
    group by Attribute
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-25
      • 2022-01-19
      • 2021-07-24
      • 2013-02-16
      • 2018-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多