hierarchical-data

T-SQL hierarchy - get breadcrumbs using query

五迷三道 提交于 2021-01-28 08:52:36
问题 I have virtual folder structure saved in database and I want to get the breadcrumbs from the current folder to the root. The data can be unsorted (but better will be sorted) and I want the parent folders of the current folder only. The table definition is: DECLARE Folders TABLE ( FOL_PK INT IDENTITY(1,1) NOT NULL, FOL_Name VARCHAR(200) NOT NULL, FOL_FOL_FK INT NULL -- Foreign key to parent ) And this is my solution: DECLARE @FOL_PK INT = 5 -- Current folder PK DECLARE @breadcrumbs TABLE ( FOL

Hierarchical Query - Counting records that belongs to Parent and Child Places

故事扮演 提交于 2021-01-27 19:33:39
问题 I have two tables PLACE and ADRESS. PLACE includes places like parent-child hierarcy. ADRESS includes adresses with PLACE_ID column. These tables as shown below; PLACE ID PARENT_ID NAME CONTINENT 11 null USA America 22 11 New York America 33 22 Manhattan America 44 null Brasil America 55 44 Rio America 66 null France Europe 77 66 Paris Europe 88 66 Nice Europe MEMBER ID PLACE_ID NAME ADRESS 1 22 .. .. 2 77 .. .. 3 33 .. .. 4 22 .. .. 5 55 .. .. 6 55 .. .. 7 88 .. .. 8 88 .. .. 9 88 .. .. 10

Update hierarchy after deletion of row

≡放荡痞女 提交于 2021-01-07 06:21:38
问题 I have a table that contains tree-like data (hierarchic design). Here is a small sample: +----+----------+-----------+-------+----------+---------+ | ID | ParentID | Hierarchy | Order | FullPath | Project | +----+----------+-----------+-------+----------+---------+ | 1 | null | 1 | 1 | 1 | 1 | | 2 | null | 2 | 2 | 2 | 1 | | 3 | 1 | 1.1 | 1 | 1-3 | 1 | | 4 | 1 | 1.2 | 2 | 1-4 | 1 | | 5 | 4 | 1.2.1 | 1 | 1-4-5 | 1 | | 6 | 2 | 2.1 | 1 | 2-6 | 1 | | 7 | null | 3 | 1 | 1 | 2 | +----+----------+---

Update hierarchy after deletion of row

隐身守侯 提交于 2021-01-07 06:21:17
问题 I have a table that contains tree-like data (hierarchic design). Here is a small sample: +----+----------+-----------+-------+----------+---------+ | ID | ParentID | Hierarchy | Order | FullPath | Project | +----+----------+-----------+-------+----------+---------+ | 1 | null | 1 | 1 | 1 | 1 | | 2 | null | 2 | 2 | 2 | 1 | | 3 | 1 | 1.1 | 1 | 1-3 | 1 | | 4 | 1 | 1.2 | 2 | 1-4 | 1 | | 5 | 4 | 1.2.1 | 1 | 1-4-5 | 1 | | 6 | 2 | 2.1 | 1 | 2-6 | 1 | | 7 | null | 3 | 1 | 1 | 2 | +----+----------+---

Plot lattice tree in Python

五迷三道 提交于 2021-01-05 06:12:09
问题 I'm seeking ideas to plot a tuple tree t = ((4,), (3, 5,), (2, 4, 6,), (1, 3, 5, 7,)) as the following image (assuming this binomial tree size can change). I'm trying to avoid dependencies on non-core packages (just sticking to pandas, numpy, matplotlib, scikit, and such). 回答1: I'm using this piece of code which gives a pretty good result: from matplotlib import pyplot as plt import numpy as np fig = plt.figure(figsize=[5, 5]) for i in range(3): x = [1, 0, 1] for j in range(i): x.append(0) x

Plot lattice tree in Python

☆樱花仙子☆ 提交于 2021-01-05 06:07:25
问题 I'm seeking ideas to plot a tuple tree t = ((4,), (3, 5,), (2, 4, 6,), (1, 3, 5, 7,)) as the following image (assuming this binomial tree size can change). I'm trying to avoid dependencies on non-core packages (just sticking to pandas, numpy, matplotlib, scikit, and such). 回答1: I'm using this piece of code which gives a pretty good result: from matplotlib import pyplot as plt import numpy as np fig = plt.figure(figsize=[5, 5]) for i in range(3): x = [1, 0, 1] for j in range(i): x.append(0) x

get parents and children of tree folder structure in my sql < 8 and no CTEs

自作多情 提交于 2020-11-30 11:08:58
问题 I have a folder table that joins to itself on an id , parent_id relationship: CREATE TABLE folders ( id int(10) unsigned NOT NULL AUTO_INCREMENT, title nvarchar(255) NOT NULL, parent_id int(10) unsigned DEFAULT NULL, PRIMARY KEY (id) ); INSERT INTO folders(id, title, parent_id) VALUES(1, 'root', null); INSERT INTO folders(id, title, parent_id) values(2, 'one', 1); INSERT INTO folders(id, title, parent_id) values(3, 'target', 2); INSERT INTO folders(id, title, parent_id) values(4, 'child one',

get parents and children of tree folder structure in my sql < 8 and no CTEs

心已入冬 提交于 2020-11-30 11:08:12
问题 I have a folder table that joins to itself on an id , parent_id relationship: CREATE TABLE folders ( id int(10) unsigned NOT NULL AUTO_INCREMENT, title nvarchar(255) NOT NULL, parent_id int(10) unsigned DEFAULT NULL, PRIMARY KEY (id) ); INSERT INTO folders(id, title, parent_id) VALUES(1, 'root', null); INSERT INTO folders(id, title, parent_id) values(2, 'one', 1); INSERT INTO folders(id, title, parent_id) values(3, 'target', 2); INSERT INTO folders(id, title, parent_id) values(4, 'child one',