I need to find teacher_id who don't have the last highest teacher (the highest must be teacher_id 7 for everyone) to whom they report using PRESTO SQL. Hierarchy depth can be greater than shown in the example dataset.
Query result must have issued teacher_id: 8,9,10,11
OUTPUT:
teacher_full_name | teacher _id |
---|---|
Jane Ortego | 8 |
Michael Powers | 9 |
Sasha Li | 10 |
Diana Norris | 11 |
Example dataset:
teacher_full_name | teacher_id | reporter_teacher |
---|---|---|
Margo Holmes | 1 | 2 |
Carry Miles | 2 | 3 |
Philipp Baskov | 3 | 4 |
Harry Potter | 4 | 5 |
Daniel Lopez | 5 | 6 |
Ivan Petrov | 6 | 7 |
Jhon Doe | 7 | |
Jane Ortego | 8 | 9 |
Michael Powers | 9 | 10 |
Sasha Li | 10 | 9 |
Diana Norris | 11 | 10 |
Wolter White | 12 | 6 |
I used PostgreSQL to realize such recursive logic but I do not know how to realize it in Presto.