
https://www.hackerrank.com/challenges/sql-projects/problem?isFullScreen=true
문제
해석
태스크의 종료_날짜가 연속이면 태스크는 동일한 프로젝트의 일부입니다. 사만다는 완료된 프로젝트의 총 개수를 찾는 데 관심이 있습니다.프로젝트를 완료하는 데 걸린 일 수를 기준으로 나열된 프로젝트의 시작 날짜와 종료 날짜를 오름차순으로 출력하는 쿼리를 작성합니다. 완료 일수가 동일한 프로젝트가 두 개 이상 있는 경우 프로젝트의 시작 날짜로 정렬합니다.
select p1.start_date , p2.end_date from ( select start_date , row_number() over (order by start_date) as rn from projects where start_date not in ( select end_date from projects) ) as p1 join ( select end_date , row_number() over (order by end_date) as rn from projects where end_date not in ( select start_date from projects) ) as p2 on p1.rn = p2.rn order by datediff(day,p1.start_date,p2.end_date) , p1.start_date