-1

enter image description here나는 나의 데이터를 포스트그레스 데이터베이스에 가지고있다. 샘플 데이터 및 필요한 출력은 다음과 같아야합니다.

이 문제를 파악하는 데 매우 어려움을 겪고 있습니다. 어떤 사람이 그림을보고 해결책을 제공 할 수 있습니까? 프로그래밍 담당자가 아니기 때문에 모든 스크립팅 언어로 코딩하는 솔루션을 제공하지 마십시오. 나는 SQL 쿼리 (postgres)를 통해 이것을 해결하거나 Excel에서 excel 수식을 사용하고 싶다.

답변

0

나는 테스트 할 postgres가 없다. (그래서 완벽하지 않을 수도있다.) 이 솔루션은 opening_id이 2를 초과하지 않는다고 가정합니다. 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