magicpin interview question

sql window function, root cause analysis