Pregunta de entrevista de Sberbank

sql query for joining 3 tables with duplicates and cte with some interval chaining logic