hierarchical-data

Closure table equivalent for graph structures in SQL

元气小坏坏 提交于 2020-01-13 11:08:28
问题 This question How to store tree structure in sql? lead to the idea of a Closure table for storing trees that is optimal in many ways. The question is is there something along these lines for graph structures in SQL. I saw this paper which seems to outline a graph index structure but it's a bit over my head. Wondering if there is a sort of way to create a few auxiliary tables to handle common queries on graph data in SQL. 回答1: I did the presentation you linked to, and I've been asked about

Closure table equivalent for graph structures in SQL

烂漫一生 提交于 2020-01-13 11:08:12
问题 This question How to store tree structure in sql? lead to the idea of a Closure table for storing trees that is optimal in many ways. The question is is there something along these lines for graph structures in SQL. I saw this paper which seems to outline a graph index structure but it's a bit over my head. Wondering if there is a sort of way to create a few auxiliary tables to handle common queries on graph data in SQL. 回答1: I did the presentation you linked to, and I've been asked about

Find node level in a tree

不羁的心 提交于 2020-01-13 09:28:14
问题 I have a tree (nested categories) stored as follows: CREATE TABLE `category` ( `category_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `category_name` varchar(100) NOT NULL, `parent_id` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`category_id`), UNIQUE KEY `category_name_UNIQUE` (`category_name`,`parent_id`), KEY `fk_category_category1` (`parent_id`,`category_id`), CONSTRAINT `fk_category_category1` FOREIGN KEY (`parent_id`) REFERENCES `category` (`category_id`) ON DELETE SET NULL ON UPDATE

How to select subcategories from selected category using a nested function in PHP?

别等时光非礼了梦想. 提交于 2020-01-12 11:11:06
问题 First of all, I posted another question about this, but didn't get answer so I needed to post a new one. I have a function which is listing categories hierarchically, I created another function (on same function) with foreach loop in, and using it into dropdowns too, so don't need to create another query, using my existing function multiple times. I want to use same query to list subcategories under a selected category. Example: if category.php?id=100 clicked, then I want to list

How to select subcategories from selected category using a nested function in PHP?

烈酒焚心 提交于 2020-01-12 11:09:16
问题 First of all, I posted another question about this, but didn't get answer so I needed to post a new one. I have a function which is listing categories hierarchically, I created another function (on same function) with foreach loop in, and using it into dropdowns too, so don't need to create another query, using my existing function multiple times. I want to use same query to list subcategories under a selected category. Example: if category.php?id=100 clicked, then I want to list

MySQL hierarchical data help - Closure Table Method

瘦欲@ 提交于 2020-01-12 07:48:06
问题 I'm trying to implement a system in MySQL to store hierarchical data. I've decided to go with the system implemented here as described by Bill Karwin starting on slide number 40. I'm trying to setup the database so the EntryPaths table is maintained automatically. Update: I've updated the database create SQL a bit. I've got things 1/2 working for an update, I think. After running the database create SQL try the following First see how this entry looks -- Example query to return a full library

postgresql procedure for finding hie parent chain

白昼怎懂夜的黑 提交于 2020-01-11 13:14:11
问题 I am new to postgresql and need a little help.I have a table named products ID Product Parent_ID 1 laptop Null 2 Camera 1 3 Iphone 1 4 Mouse 2 5 Printer 2 6 Scanner 3 7 HardDisk 3 I want to create a function in postgres to get the hierarchy of the parent chain of any value i pass like if i pass 4 then my output should be id parent_id 1 Null 2 1 4 2 回答1: I would suggest to use "recursive with" clause. Kindly check below query. WITH RECURSIVE recursiveTable AS ( SELECT id, parent_id FROM table

Generating Depth based tree from Hierarchical Data in MySQL (no CTEs)

旧街凉风 提交于 2020-01-08 08:50:19
问题 Hi For many days I have been working on this problem in MySQL, however I can not figure it out. Do any of you have suggestions? Basically, I have a category table with domains like: id , name (name of category), and parent (id of parent of the category). Example Data: 1 Fruit 0 2 Apple 1 3 pear 1 4 FujiApple 2 5 AusApple 2 6 SydneyAPPLE 5 .... There are many levels, possibly more than 3 levels. I want to create an sql query that groups the datas according to he hierarchy: parent > child >

Sorting a dictionary both hierarchically and alphabetically (Python)

被刻印的时光 ゝ 提交于 2020-01-07 05:46:10
问题 I am using a Python dictionary (product_dict) to represent a hierarchy of a product and all its subparts. The dict's keys are unique IDs (UUID), and the values are Class objects containing all information about those parts, including: part.name # A string, containing the actual name of a component part.idCode # UUID of component part.parent # UUID of parent component part.children # List of UUIDs of child components part.tier # An integer that specifies its tier/level within the hierarchy Now

Extracting specific data from hierarchical-data in R

我们两清 提交于 2020-01-07 05:30:31
问题 I have a dataframe made up of 6 columns. Columns 1 to 5 each have discrete names/values, such as a district, year, month, age interval and gender. The sixth column is the number of death counts for that specific combination. District Gender Year Month Age.Group Total.Deaths 1 Eastern Female 2003 1 -1 0 2 Eastern Female 2003 1 -2 2 3 Eastern Female 2003 1 0 2 4 Eastern Female 2003 1 01-4 1 5 Eastern Female 2003 1 05-09 0 6 Eastern Female 2003 1 10-14 1 7 Eastern Female 2003 1 15-19 0 8 Eastern