다음과 같은 테이블에 표시된 데이터가 있습니다.
사용자 | 유형 | 데이트 |
---|---|---|
ㅏ | 변하기 쉬운 | 2019-01-10 |
ㅏ | 변하기 쉬운 | 2019-01-20 |
ㅏ | 데스크탑 | 2019-03-01 |
ㅏ | 데스크탑 | 2019-03-20 |
PostgreSQL (특히 Snowflake 쿼리 도구) 사용-다음을 달성하고 싶습니다.
사용자 | First_Type | 첫 번째 유형 초기 날짜 | Second_Type | 두 번째 유형 초기 날짜 |
---|---|---|---|---|
ㅏ | 변하기 쉬운 | 2019-01-10 | 데스크탑 | 2019-03-01 |
흠. . . row_number()
(두 번) 및 집계를 사용할 수 있습니다 .
select user,
max(case when seqnum_u = 1 then type end) as type1,
max(case when seqnum_u = 1 then date end) as date1,
max(case when seqnum_u = 2 then type end) as type2,
max(case when seqnum_u = 2 then date end) as date2
from (select t.*,
row_number() over (partition by user order by date) as seqnum_u
from (select t.*,
row_number() over (partition by user, type order by date) as seqnum
from t
) t
where seqnum = 1
) t
group by user;
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다