J.P. Morgan interview question

expect tough questions on sql query