【问题标题】:I have my data in postgres database. Sample data and required output should look like below我在 postgres 数据库中有我的数据。示例数据和所需输出应如下所示
【发布时间】:2016-09-14 00:11:34
【问题描述】:

enter image description here

我很难弄清楚这一点。有人可以看看图片并提供解决方案。 请不要提供涉及使用任何脚本语言进行编码的解决方案,因为我不是编程人员。 我想通过 sql 查询(postgres)或在 excel 中使用 excel 公式来解决这个问题。

【问题讨论】:

    标签: excel postgresql excel-formula postgresql-9.1 postgresql-9.3


    【解决方案1】:

    我没有要测试的 postgres(所以这可能并不完美)。此解决方案假定opening_id 不超过两个locations

    Select 
    t1.opening_id
    Case when t2.Num >1 THEN 
    CONCAT(t1.location,' | ',t2.location)
    ELSE t1.location END as location
    ,AVG(t1.days_open,t2.days_open) as days_open
    ,t1.age_band
    from table t1
    INNER JOIN(
               Select 
               opening_id
               ,location
               ,AVG(days_open)
               ,COUNT(distinct location) as Num
               from table
               Group by opening_id
                       ,location
               )t2
    ON t1.opening_id=t2.opening_id
    Group by 
            t1.opening_id
           ,t2.Num
           ,CONCAT(t1.location,'|',t2.location)
           ,t1.location
           ,t1.age_band
    

    【讨论】:

      猜你喜欢
      • 2021-05-16
      • 1970-01-01
      • 2021-07-27
      • 2021-10-13
      • 1970-01-01
      • 2013-07-25
      • 2013-07-18
      • 1970-01-01
      • 2015-04-04
      相关资源
      最近更新 更多