Pregunta de entrevista de Bayer

Please write the sql solution for questions.