Teradata and SQL Server : how to get hierarchy

51 Views Asked by At

In Teradata/SQL Server, how to get by SQL/BTEQ the hierarchical top parent?

  • Head teacher is minimum id among all the teacher of the student.
  • if student 10 has 3 teachers 1,8,9; teacher (id) 8 & 9 are also students, and student 8 & 9 will have teacher 1/ i.e. minimum teaches same as 10 has

Say for following input, how can we get the desired output?

Input:

enter image description here

Desired output:

enter image description here

0

There are 0 best solutions below