由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - recursive sql?
相关主题
1. Oracle vs. SQL92 Re: Just请教一个mysql 排序问题。
这个sql语句怎么写a sql question
SQL combine two columns from two different tables no shared (转载)How to get other columns after UNION?
[转载] what's wrong with this PL/SQLrecursive query help
help about SQL for ACCESSRookie's question again
One sql question help!一个关于T-SQL的问题
ask for help with a simple query!!!请教SQL server的一个programming的问题,谢谢
两个列联合作Primary Key,还需要单独建index吗?How to write this query in Oracle?
相关话题的讨论汇总
话题: recursive话题: parent话题: select话题: children话题: subparts
进入Database版参与讨论
1 (共1页)
b****e
发帖数: 1275
1
i have a question..
if i have a table which has two columns, parent_id and child_id
which is used to represent a tree structure.. ie.. there're many
levels.. and each node can have many children.. but only 1 parent.
so, records would be like (1, 2), (1, 3), (1, 4), (2, 5), (2, 6),
(3, 7), (5,8) etc etc
now how do you select all leaf level children of a known parent_id?
what about selecting all children that are <=x levels below the
parent_id?
i guess there must be a recursive way of doing this..
w*****h
发帖数: 139
2
This is a typical BOM question.
SQL99 already supports recursive SQL.
You have a table: assembly(part, subpart,...)
CREATE RECURSIVE view all_subparts(Major, Minor) AS
SELECT PART SUBPART
FROM assembly
UNION
SELECT all.Major assb.SUBPART
FROM all_subparts all, assembly assb
WHERE all.minor = assb.PART
SELECT * FROM all_subparts

【在 b****e 的大作中提到】
: i have a question..
: if i have a table which has two columns, parent_id and child_id
: which is used to represent a tree structure.. ie.. there're many
: levels.. and each node can have many children.. but only 1 parent.
: so, records would be like (1, 2), (1, 3), (1, 4), (2, 5), (2, 6),
: (3, 7), (5,8) etc etc
: now how do you select all leaf level children of a known parent_id?
: what about selecting all children that are <=x levels below the
: parent_id?
: i guess there must be a recursive way of doing this..

1 (共1页)
进入Database版参与讨论
相关主题
How to write this query in Oracle?help about SQL for ACCESS
Help on Oracle QueryOne sql question help!
Oracle,table有上千个columnask for help with a simple query!!!
random error for CAST( MONEY AS VARCHAR)两个列联合作Primary Key,还需要单独建index吗?
1. Oracle vs. SQL92 Re: Just请教一个mysql 排序问题。
这个sql语句怎么写a sql question
SQL combine two columns from two different tables no shared (转载)How to get other columns after UNION?
[转载] what's wrong with this PL/SQLrecursive query help
相关话题的讨论汇总
话题: recursive话题: parent话题: select话题: children话题: subparts