Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Profundidade em MYSQL e árvores de tabelas de fechamento


Adicione profundidade+1 ao primeiro SELECT.
INSERT INTO closure_tree_path (ancestor, descendant, depth)
SELECT ancestor, '{$node_id}', depth+1 FROM closure_tree_path
WHERE descendant = '{$parent_id}'
UNION ALL SELECT '{$node_id}', '{$node_id}', 0;