Leser: 19
1
2
3
4
5
6
7
SELECT n.name,
COUNT(*)-1 AS level
FROM tree AS n,
tree AS p
WHERE n.lft BETWEEN p.lft AND p.rgt
GROUP BY n.lft
ORDER BY n.lft;
1 2 3 4 5 6 7 8 9 10 11 12
my @levels; while (my $row = $sth->fetchrow_hashref) { my $level = $row->{level}; $levels[$level]++; local $" = "."; print "@levels[0 .. $level] $row->{ident}\n"; } __END__ 1 root 1.1 a 1.1.1 b 1.2 c