|
-- insert level 0 |
|
insert into tree |
|
SELECT handle, id, name, cant, CONCAT('.', id,'.'), CONCAT('.', handle,'.'), depth |
|
FROM cant_per_com cp |
|
WHERE depth = 0; |
|
|
|
-- insert level 1 |
|
insert into tree |
|
SELECT cp.handle, cp.id, cp.name, cp.cant, CONCAT(t.uuid_path, cp.id, '.'), CONCAT(t.path, cp.handle, '.'), cp.depth |
|
--SELECT handle, name, CONCAT(handle), cant, depth |
|
FROM cant_per_com cp |
|
INNER JOIN tree t on cp.handle_padre = t.handle |
|
WHERE cp.depth = 1 -- and cp.handle = '10915/41' |
|
ORDER BY cp.handle_padre, cp.handle; |
|
|
|
-- insert level 2 |
|
insert into tree |
|
SELECT cp.handle, cp.id, cp.name, cp.cant, CONCAT(t.uuid_path, cp.id, '.'), CONCAT(t.path, cp.handle, '.'), cp.depth |
|
FROM cant_per_com cp |
|
INNER JOIN tree t on cp.handle_padre = t.handle |
|
WHERE cp.depth = 2 |
|
ORDER BY cp.handle_padre, cp.handle; |
|
|
|
-- insert level 3 |
|
insert into tree |
|
SELECT cp.handle, cp.id, cp.name, cp.cant, CONCAT(t.uuid_path, cp.id, '.'), CONCAT(t.path, cp.handle, '.'), cp.depth |
|
FROM cant_per_com cp |
|
INNER JOIN tree t on cp.handle_padre = t.handle |
|
WHERE cp.depth = 3 |
|
ORDER BY cp.handle_padre, cp.handle; |
|
|
|
-- insert level 4 |
|
insert into tree |
|
SELECT cp.handle, cp.id, cp.name, cp.cant, CONCAT(t.uuid_path, cp.id, '.'), CONCAT(t.path, cp.handle, '.'), cp.depth |
|
FROM cant_per_com cp |
|
INNER JOIN tree t on cp.handle_padre = t.handle |
|
WHERE cp.depth = 4 |
|
ORDER BY cp.handle_padre, cp.handle; |