Morgan Stanley interview question

Write a query in SQL