Following is my Sample data1
CP | NP |MC |DS |NNP
--- ---- --- -- ---
A | B | | |C
C | D | XX|YY |E
E | F | ZZ|11 |
Expected Output1
NP |MC |DS
--- ---- ---
B | ZZ|11
Here column "CP" and "NNP" are hierarchical (i.e.) we will start with query like below, for a particular NP and then get the corresponding MC and DS values using the below logic
select MC, DS from tabl1
where NP=B
- first look at value A from column CP and then see if column NNP as a corresponding value, here it is C value in column NNP
- if there is a corresponding values form column CP present in NNP then look at column CP for C value and then see if NNP as corresponding value here it is E value in column NNP (repeated these steps until we do not find a corresponding entry in NNP column for column CP)
- fetch E value corresponding values for column MC and DS
Following is my Sample data2
CP | NP |MC |DS |NNP
--- ---- --- -- ---
A | B | 96|KK |C
C | D | XX|YY |E
E | F | ZZ|11 |
Expected Output2 (if the corresponding root values are not null then we need to fetch those as well
NP |MC |DS
--- ---- ---
B | 96|KK
B | ZZ|11