How to get sql result for missing tree level?

时间:2018-02-26 17:51:56

标签: sql oracle

i have a tree with let's assume 14 levels but there are some gaps in tree branch like

tree values a>b>..>h>i>..>k>l>..>n
tree level:=1 2  8 9 11 12 14

need to get the result like

a>b>h>h>h>h>h>i>k>k>l>n>n>
1 2 3 4 5 6 7 8 9 10 11 12 13 14

basically i have a table with 7 records so need 14 records in single query i have primary key or tree level as specified.

agent_id,commission,lvl,amount  
a,1%,1,500  
b,1%,2,500  
h,1%,8,500  
i,1%,9,500  
k,1%,11,500  
l,1%,12,500  
n,1%,13,500  

it is a tree to table mapping and i am just giving single branch not to complicate it further.

result should be

 a (5+5+5+5+5+5+5)=35
 b (5+5+5+5+5+5+5+5+5+5+5)=55
 h (5+5+5+5+5)=25
 i (5+5+5+5+5)=25
 k (5+5+5)=15
 l (5+5+5)=15
 n 5

i need to give commission to N on 500-1% then for L on (500(n)+500(gap)+500(l))-1% but then the empty tree node M should not be considered for others commission but then again for K (500(n)+500(l)+500(k))1% and so on till agent A so for B need to consider for empty agents commission also but only for lvl 3,4,5,6,7.

0 个答案:

没有答案