![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
Modifying Celko's Adjaceny List example to a table containing a transitive closure of a tree (without pathlength): Expected order by hierarchy: Albert Bert Chuck Donna Eddie George Fred Herbert I'd like to know if there's a _single_ SQL statement to retrieve that result set? |
#2
| |||
| |||
|
|
Modifying Celko's Adjaceny List example to a table containing a transitive closure of a tree (without pathlength): CREATE TABLE OrgChart (emp CHAR(10) NOT NULL, boss CHAR(10) NOT NULL, PRIMARY KEY (emp, boss) ); INSERT INTO OrgChart VALUES('Bert', 'Albert'); INSERT INTO OrgChart VALUES('Chuck', 'Albert'); INSERT INTO OrgChart VALUES('Donna', 'Albert'); INSERT INTO OrgChart VALUES('Donna', 'Chuck'); INSERT INTO OrgChart VALUES('Eddie', 'Albert'); INSERT INTO OrgChart VALUES('Eddie', 'Chuck'); INSERT INTO OrgChart VALUES('Fred', 'Albert'); INSERT INTO OrgChart VALUES('Fred', 'Chuck'); INSERT INTO OrgChart VALUES('Herbert','Albert'); INSERT INTO OrgChart VALUES('George', 'Albert'); INSERT INTO OrgChart VALUES('George', 'Chuck'); INSERT INTO OrgChart VALUES('George', 'Eddie'); Expected order by hierarchy: Albert Bert Chuck Donna Eddie George Fred Herbert I'd like to know if there's a _single_ SQL statement to retrieve that result set? Dieter |
#3
| |||
| |||
|
|
Dieter Nöth <dnoeth (AT) gmx (DOT) de> wrote (abridged) Modifying Celko's Adjaceny List example to a table containing a transitive closure of a tree (without pathlength): Expected order by hierarchy: Albert Bert Chuck Donna Eddie George Fred Herbert I'd like to know if there's a _single_ SQL statement to retrieve that result set? If you know transitive closure, then you can answer the following mini-questions: 1. Is B parent of A? 2. Find all the ancestors of A. 3. How many ancestors A have? 4. What is immediate parent of A? 5. Do A and B have the same parent? |
|
6. For any nodes A and B we write A > B whenever i. B is parent of A or ii. there exists node B' which is an ancestor of B, and A' which is an ancestor of A, and both A' and B' having the same parent, and A' > B' 7. For any node A, the depth first enumeration number is the number of nodes that are predecessors of A with the ordering defined at the step# 6. |
#4
| |||
| |||
|
|
"Vadim Tropashko" <vadimtro (AT) yahoo (DOT) com> wrote in message |
|
6. For any nodes A and B we write A > B whenever i. B is parent of A or ii. there exists node B' which is an ancestor of B, and A' which is an ancestor of A, and both A' and B' having the same parent, and A' > B' 7. For any node A, the depth first enumeration number is the number of nodes that are predecessors of A with the ordering defined at the step# 6. create view DepthFirst as ( select boss lesser, emp greater from OrgChart union select distinct n1.name, n2.name from nodes n1, nodes n2, nodes n01, nodes n02 where n01.reportsTo = n02.reportsTo and n01.name < n02.name and (n01.name=n1.name or n01.name in (select boss from OrgChart where emp = n1.name)) and (n02.name=n2.name or n02.name in (select boss from OrgChart where emp = n2.name)) ) |
#5
| |||
| |||
|
|
I'd like to know if there's a _single_ SQL statement to retrieve that result set? |

#6
| |||
| |||
|
|
"Vadim Tropashko" <vadimtro (AT) yahoo (DOT) com> wrote in message news:22d2e427.0308172007.7eb298f (AT) posting (DOT) google.com... Dieter Nöth <dnoeth (AT) gmx (DOT) de> wrote in message news:<bhooo1$1kdal$1 (AT) ID-28204 (DOT) news.uni-berlin.de>... |
|
6. For any nodes A and B we write A > B whenever i. B is parent of A or ii. there exists node B' which is an ancestor of B, and A' which is an ancestor of A, and both A' and B' having the same parent, and A' > B' 7. For any node A, the depth first enumeration number is the number of nodes that are predecessors of A with the ordering defined at the step# 6. |
#7
| |||
| |||
|
|
"Mikito Harakiri" <mikharakiri (AT) ywho (DOT) com> wrote "Vadim Tropashko" <vadimtro (AT) yahoo (DOT) com> wrote in message news:22d2e427.0308172007.7eb298f (AT) posting (DOT) google.com... Dieter Nöth <dnoeth (AT) gmx (DOT) de> wrote in message news:<bhooo1$1kdal$1 (AT) ID-28204 (DOT) news.uni-berlin.de>... Vadimtro (Mikito?). Shouldnt 6. be changed to |
#8
| |||
| |||
|
|
"Mikito Harakiri" <mikharakiri (AT) ywho (DOT) com> wrote "Vadim Tropashko" <vadimtro (AT) yahoo (DOT) com> wrote in message news:22d2e427.0308172007.7eb298f (AT) posting (DOT) google.com... Dieter Nöth <dnoeth (AT) gmx (DOT) de> wrote in message news:<bhooo1$1kdal$1 (AT) ID-28204 (DOT) news.uni-berlin.de>... Vadimtro (Mikito?). Shouldnt 6. be changed to 6. For any nodes A and B we write A > B whenever i. B is an ancestor of A or ... ? I noticed that Mikito used the OrgChart (ancestor) relation, and when I played a round with a similar thing myself, some tuples are missing in my "total_order" relation using parent. [...] Kind regards /Lennart 6. For any nodes A and B we write A > B whenever i. B is parent of A or ii. there exists node B' which is an ancestor of B, and A' which is an ancestor of A, and both A' and B' having the same parent, and A' > B' 7. For any node A, the depth first enumeration number is the number of nodes that are predecessors of A with the ordering defined at the step# 6. [...] |
![]() |
| Thread Tools | |
| Display Modes | |
| |