Amazon interview question

sql hard level leetcode question