Medium: Question 5

 avatar
user_0571526250
mysql
2 years ago
570 B
1
Indexable
Never
/*
Question 5: Medium Part
*/
SELECT start_date,
       ADDDATE(start_date, days) AS end_date
FROM
  (SELECT s.start_date,
          MIN(DATEDIFF(e.end_date, s.start_date)) AS days
   FROM
     (SELECT start_date
      FROM projects
      WHERE start_date NOT IN
          (SELECT end_date
           FROM projects) ) s
   CROSS JOIN
     (SELECT end_date
      FROM projects
      WHERE end_date NOT IN
          (SELECT start_date
           FROM projects) ) e
   WHERE s.start_date < e.end_date
   GROUP BY s.start_date) AS RESULT
ORDER BY days,
         start_date;