Tecnotree interview question

SQL query