NTree Example: Find Employee Management Chain | Teradata Vantage - NTree Example: Find Employee Management Chain - Teradata Vantage

Machine Learning Engine Analytic Function Reference

Product
Teradata Vantage
Release Number
9.02
9.01
2.0
1.3
Published
February 2022
Language
English (United States)
Last Update
2022-02-10
dita:mapPath
rnn1580259159235.ditamap
dita:ditavalPath
ybt1582220416951.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
  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.