hierarchical-data

How to create a MySQL hierarchical recursive query?

旧巷老猫 提交于 2021-02-17 07:05:12
问题 I have a MySQL table which is as follows: id name parent_id 19 category1 0 20 category2 19 21 category3 20 22 category4 21 ... ... ... Now, I want to have a single MySQL query to which I simply supply the id [for instance say id=19 ] then I should get all its child ids [i.e. result should have ids '20,21,22'].... The hierarchy of the children is not known; it can vary.... I know how to do it using a for loop... but how to achieve the same using a single MySQL query? 回答1: For MySQL 8+: use the

PostgreSQL recursive parent/child query

馋奶兔 提交于 2021-02-16 08:33:38
问题 I'm having some trouble working out the PostgreSQL documentation for recursive queries, and wonder if anyone might be able to offer a suggestion for the following. Here's the data: Table "public.subjects" Column | Type | Collation | Nullable | Default -------------------+-----------------------------+-----------+----------+-------------------------------------- id | bigint | | not null | nextval('subjects_id_seq'::regclass) name | character varying | | | Table "public.subject_associations"

PostgreSQL recursive parent/child query

老子叫甜甜 提交于 2021-02-16 08:32:00
问题 I'm having some trouble working out the PostgreSQL documentation for recursive queries, and wonder if anyone might be able to offer a suggestion for the following. Here's the data: Table "public.subjects" Column | Type | Collation | Nullable | Default -------------------+-----------------------------+-----------+----------+-------------------------------------- id | bigint | | not null | nextval('subjects_id_seq'::regclass) name | character varying | | | Table "public.subject_associations"

How to build a JSON object using collection of dot notation strings using JavaScript?

ⅰ亾dé卋堺 提交于 2021-02-11 18:19:43
问题 I have a collection of strings in an array. These strings are the JSON paths that i select from a checkbox tree. var selected = ['a', 'b.c.0.d', 'b.c.1.d', 'b.c.0.e', 'b.c.1.e']; I want to save it to the database with the real data given by the user. So i want to create a JSON object like following structure. It can be further nested. { "a":5, "b":{ "c":[ { "d":5, "e":5 }, { "d":5, "e":5 } ] } } 来源: https://stackoverflow.com/questions/59882169/how-to-build-a-json-object-using-collection-of

How to build a JSON object using collection of dot notation strings using JavaScript?

久未见 提交于 2021-02-11 18:18:18
问题 I have a collection of strings in an array. These strings are the JSON paths that i select from a checkbox tree. var selected = ['a', 'b.c.0.d', 'b.c.1.d', 'b.c.0.e', 'b.c.1.e']; I want to save it to the database with the real data given by the user. So i want to create a JSON object like following structure. It can be further nested. { "a":5, "b":{ "c":[ { "d":5, "e":5 }, { "d":5, "e":5 } ] } } 来源: https://stackoverflow.com/questions/59882169/how-to-build-a-json-object-using-collection-of

d3 based multiple sub groups of a bar chart

孤街浪徒 提交于 2021-02-10 06:10:24
问题 I am trying to produce a bar graph that has multiple hierarchical / groupings of factors using d3.js . An example from excel of what I am attempting to create, subgrouped by Variety and Irrigation treatment: I have searched for quite some time and have yet to see an example of something like the example graph above. The closet I found is this (as well as this, this, and this). but they all lack the one more level of grouping that I need. Is there a way to create multiple groupings in d3.js ,

sql select parent child recursive in one field

我的未来我决定 提交于 2021-02-07 01:59:08
问题 I do not know how to select query recursive.. id idparent jobNO -------------------------------- 1 0 1 2 1 2 3 1 3 4 0 4 5 4 5 6 4 6 how do the results like this With SqlServer id idparent jobNO ListJob ---------------------------------------- 1 0 1 1 2 1 2 1/2 3 1 3 1/3 4 0 4 4 5 4 5 4/5 6 5 6 4/5/6 回答1: You need to use a Recursive Common Table Expression. There are many useful articles online. Useful Links Simple Talk: SQL Server CTE Basics blog.sqlauthority: Recursive CTE Here is a

Converting flat hierarchy to nested hierarchy in XSLT depth

*爱你&永不变心* 提交于 2021-02-04 21:13:48
问题 I have some frustratingly flat XML that looks like this: <groups> <group id="1" depth="1" /> <group id="2" depth="2" /> <group id="3" depth="2" /> <group id="4" depth="3" /> <group id="5" depth="2" /> <group id="6" depth="3" /> </groups> The maximum value of depth appears to be 5 . Which I'd like to turn into XML that looks like this: <groups> <group id="1" depth="1"> <group id="2" depth="2"> </group> <group id="3" depth="2"> <group id="4" depth="3"> </group> </group> <group id="5" depth="2">

Converting flat hierarchy to nested hierarchy in XSLT depth

偶尔善良 提交于 2021-02-04 21:13:06
问题 I have some frustratingly flat XML that looks like this: <groups> <group id="1" depth="1" /> <group id="2" depth="2" /> <group id="3" depth="2" /> <group id="4" depth="3" /> <group id="5" depth="2" /> <group id="6" depth="3" /> </groups> The maximum value of depth appears to be 5 . Which I'd like to turn into XML that looks like this: <groups> <group id="1" depth="1"> <group id="2" depth="2"> </group> <group id="3" depth="2"> <group id="4" depth="3"> </group> </group> <group id="5" depth="2">

String to Hierarchical List

百般思念 提交于 2021-01-29 07:36:52
问题 I'm trying to convert a string into a hierarchical list where each line in the string represents a single item within the hierarchy. For example say I have the following string: 1 - First Level 1 2 - First Level 1 > Second Level 1 3 - First Level 1 > Second Level 1 > Third Level 1 4 - First Level 1 > Second Level 2 5 - First Level 2 6 - First Level 2 > Second Level 1 7 - First Level 2 > Second Level 1 > Third Level 1 ... I need to convert it to a list of the following type: public class