NTree Example 2: Find Employee Management Chain - Teradata Vantage

Machine Learning Engine Analytic Function Reference

Product
Teradata Vantage
Release Number
8.00
1.0
Published
May 2019
Language
English (United States)
Last Update
2019-11-22
dita:mapPath
blj1506016597986.ditamap
dita:ditavalPath
blj1506016597986.ditaval
dita:id
B700-4003
lifecycle
previous
Product Category
Teradata Vantage™

Input

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
  Root_Node (mgr_id IS NULL)
  Node_ID (emp_id)
  Parent_ID (mgr_id)
  Starts_With (emp_id=500) 
  Mode ('up') 
  Output ('end')
  Result (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