REAL SQL Interview Problem | Hierarchical data in SQL