UBS interview question

SQl query question