darwinLabs interview question

How I would a SQL for a specific scenario