Quantcast
Channel: Teradata Forums - All forums
Viewing all articles
Browse latest Browse all 27759

With Recursive - how to filter duplicate records? - response (1) by KS42982

$
0
0

I think to find out the last level, you first need to create rank based on mgr_id, emp_id and staff_id and put it in employee table/view. Let's call is 'RNK'. Once that is done, you can change your recursive view like below.
REPLACE RECURSIVE VIEW emp_hier1 (E_RNK, mgr_id, emp_id, staff_id, path) AS
(
SELECT RNK E_RNK, a.mgr_id, a.emp_id, a.staff_id,
CAST (TRIM(a.staff_id) AS VARCHAR(200)) AS path
FROM  employee a
WHERE a.mgr_id IS NULL
AND RNK = 1
UNION ALL
SELECT b.RNK E_RNK, b.mgr_id, b.emp_id, b.staff_id, CAST (TRIM(c.path) || '~+~' || TRIM(b.staff_id) AS VARCHAR(200)) AS path
FROM
 employee b ,
 emp_hier1 c
WHERE b.mgr_id = c.emp_id
AND c.E_RNK + 1 = b.RNK) ;

(I don't have access to data, so there might be some syntax error(s), but you can fix that.)
Now, if you SELECT E_RNK and Path, you will get the last level.
Regarding your second question, really don't get on what criteria you want to get rid of BOLD records. Please explain the condition and would try to help.


Viewing all articles
Browse latest Browse all 27759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>