Input
- employee_table, as in NTree Example: Find Employee Reports
SQL Call
This call finds the management chain of employee 500 by traversing the tree of employees from employee 500 upward.
SELECT * FROM NTree@coprocessor ( ON employee_table PARTITION BY 1 USING RootNode (mgr_id IS NULL) NodeID (emp_id) ParentID (mgr_id) Direction ('Up') StartsWith (emp_id=500) OutputType ('END') Results (PATH(emp_name) AS path) ) AS dt ORDER BY 1;
Output
The output table shows that employee 500, Fred, reports to Kim, who reports to Pat, who reports to Don.
id path --- ------------------- 100 fred->kim->pat->don
Download a zip file of all examples and a SQL script file that creates their input tables from the attachment in the left sidebar.