【发布时间】:2016-09-14 00:11:34
【问题描述】:
我很难弄清楚这一点。有人可以看看图片并提供解决方案。 请不要提供涉及使用任何脚本语言进行编码的解决方案,因为我不是编程人员。 我想通过 sql 查询(postgres)或在 excel 中使用 excel 公式来解决这个问题。
【问题讨论】:
标签: excel postgresql excel-formula postgresql-9.1 postgresql-9.3
我很难弄清楚这一点。有人可以看看图片并提供解决方案。 请不要提供涉及使用任何脚本语言进行编码的解决方案,因为我不是编程人员。 我想通过 sql 查询(postgres)或在 excel 中使用 excel 公式来解决这个问题。
【问题讨论】:
标签: excel postgresql excel-formula postgresql-9.1 postgresql-9.3
我没有要测试的 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
【讨论】: