UBS interview question

Writing a query for SQL database