: .
SQLFiddle, , .
:
id, path
1, '1'
2, '1\2'
3, '1\3'
4, '1\4'
5, '1\5'
6, '1\6'
7, '1\7'
8, '1\8'
9, '1\9'
10, '1\10'
(id = 10) :
SELECT TOP 1
id,
path
FROM hierarchy
ORDER BY path DESC
:
id, path
9, 1\9
path , 1\10 1\9 (. ).
, , , , :
path depth length
12\3\11\2 4 9
5\17\10\1 4 9
- .
, 26- 10-:
SQLFiddle
, , django, , , , , - path, .
EDIT - , , :
- " " - , (.. ). a node 10 , , ? , .
- " " , , node :
1
/ \
1\1 1\2 <= This is the rightmost node
/
1\1\1 <= This is the lowest node
- " ", node:
function GetRightmostNode(Node startNode)
{
Node currentNode = startNode;
while(currentNode.RightChildren != null)
{
currentNode = maximum of currentNode.RightChildren;
}
return currentNode;
}
node node. , . node - , node, node ( ) startNode .