Question d’entretien chez Sberbank

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