Maventic interview question

asked to write some sql query