transitive-closure-table

Sorting a subtree in a closure table hierarchical-data structure

二次信任 提交于 2019-11-27 18:37:09
I would like to ask you to help me with the problem with sorting of the hierarchical data structure stored as a closure table . I wanted to use this structure to store my website menu. Everything works fine, but the problem is that I do not know how to sort the exact subtree in a custom order. At the moment the tree is sorted in the order in which the items were added to the database. My structure is based on Bill Karwin's article about Closure Tables and some other posts. Here is my MySQL database structure with some DEMO data: -- -- Table `category` -- CREATE TABLE IF NOT EXISTS `category` (

MySQL Closure Table hierarchical database - How to pull information out in the correct order

对着背影说爱祢 提交于 2019-11-27 11:09:22
I have a MySQL database holding hierarchical data using the Closure Table method. A simple sample database create script follows the question. My issue at the moment is how do I pull data out of the database in the correct order? I'm currently using the following select statement. SELECT `TreeData`.`iD`, `TreeData`.`subsectionOf`, CONCAT(REPEAT('-', `TreePaths`.`len`),`TreeData`.`name`), `TreePaths`.`len`,`TreePaths`.`ancestor`,`TreePaths`.`descendant` FROM `TreeData` LEFT JOIN `TreePaths` ON `TreeData`.`iD` = `TreePaths`.`descendant` WHERE `TreePaths`.`ancestor` = 1 ORDER BY `TreeData`.

How to get the parent given a child in SQL SERVER 2005

两盒软妹~` 提交于 2019-11-26 21:43:08
问题 I have a table like this childid parentid ------------------------ 1 0 2 1 3 2 4 2 5 3 6 4 7 0 8 7 9 8 10 1 If I give a childid as 5, the parentid will be 1(output) If I give a childid as 9, the parentid will be 7.(output) i.e. the root parentid is 0 and the query should stop there. How to solve such a query? Please help. 回答1: I think you should rename your child_id to node, your parent_id to child_of. Your column naming is a bit confusing create table stack_overflow ( node int, child_of int

Sorting a subtree in a closure table hierarchical-data structure

蓝咒 提交于 2019-11-26 19:32:18
问题 I would like to ask you to help me with the problem with sorting of the hierarchical data structure stored as a closure table . I wanted to use this structure to store my website menu. Everything works fine, but the problem is that I do not know how to sort the exact subtree in a custom order. At the moment the tree is sorted in the order in which the items were added to the database. My structure is based on Bill Karwin's article about Closure Tables and some other posts. Here is my MySQL

MySQL Closure Table hierarchical database - How to pull information out in the correct order

给你一囗甜甜゛ 提交于 2019-11-26 17:59:23
问题 I have a MySQL database holding hierarchical data using the Closure Table method. A simple sample database create script follows the question. My issue at the moment is how do I pull data out of the database in the correct order? I'm currently using the following select statement. SELECT `TreeData`.`iD`, `TreeData`.`subsectionOf`, CONCAT(REPEAT('-', `TreePaths`.`len`),`TreeData`.`name`), `TreePaths`.`len`,`TreePaths`.`ancestor`,`TreePaths`.`descendant` FROM `TreeData` LEFT JOIN `TreePaths` ON