UBS interview question

Question on aggregate function on sql