connect-by

Oracle Self-Join on multiple possible column matches - CONNECT BY?

為{幸葍}努か 提交于 2020-01-13 05:07:09
问题 I have a query requirement from ----. Trying to solve it with CONNECT BY , but can't seem to get the results I need. Table (simplified): create table CSS.USER_DESC ( USER_ID VARCHAR2(30) not null, NEW_USER_ID VARCHAR2(30), GLOBAL_HR_ID CHAR(8) ) -- USER_ID is the primary key -- NEW_USER_ID is a self-referencing key -- GLOBAL_HR_ID is an ID field from another system There are two sources of user data (datafeeds)... I have to watch for mistakes in either of them when updating information.

Hierarchical Query Needs to Pull Children, Parents and Siblings

被刻印的时光 ゝ 提交于 2020-01-13 02:47:08
问题 Can now pull the data, but am wondering if there is a better way to optimize the query for large data sets. http://sqlfiddle.com/#!4/0ef0c/5 So basically I want to be able to supply the query a given org id and have it recursively pull its parents, its children, its siblings and its aunts and uncles. And then pull any Activities that are associated with that org hierarchy. Org1 is the top level org, but it may or may not have a null parent. Basically I was doing an up and down query to pull

Joining other tables in oracle tree queries

百般思念 提交于 2020-01-02 01:55:11
问题 Given a simple (id, description) table t1, such as id description -- ----------- 1 Alice 2 Bob 3 Carol 4 David 5 Erica 6 Fred And a parent-child relationship table t2, such as parent child ------ ----- 1 2 1 3 4 5 5 6 Oracle offers a way of traversing this as a tree with some custom syntax extensions: select parent, child, sys_connect_by_path(child, '/') as "path" from t2 connect by prior parent = child The exact syntax is not important, and I've probably made a mistake in the above. The

Recursive SQL and information on different level

隐身守侯 提交于 2019-12-31 07:42:07
问题 Is it possible to display, in the same query, information concerning different level of recursivity ? select LEVEL, ae2.CAB, ae2.NIVEAU, ae2.ENTITE, ae2.ENTITE_PARENT, ae2.libelle from my_table ae2 where ae2.NIVEAU = 2 start with ae2.cab = 'XXX' connect by prior ae2.entite_parent = ae2.entite With this query I have (let's say) 4 levels of information about the entity above root 'XXX' Is it possible to display root information at the same time? 回答1: Yes, it's possible to use the CONNECT_BY

Recursive SQL and information on different level

隐身守侯 提交于 2019-12-31 07:42:06
问题 Is it possible to display, in the same query, information concerning different level of recursivity ? select LEVEL, ae2.CAB, ae2.NIVEAU, ae2.ENTITE, ae2.ENTITE_PARENT, ae2.libelle from my_table ae2 where ae2.NIVEAU = 2 start with ae2.cab = 'XXX' connect by prior ae2.entite_parent = ae2.entite With this query I have (let's say) 4 levels of information about the entity above root 'XXX' Is it possible to display root information at the same time? 回答1: Yes, it's possible to use the CONNECT_BY

SQL Server Equivalent of Oracle 'CONNECT BY PRIOR', and 'ORDER SIBLINGS BY'

那年仲夏 提交于 2019-12-28 12:06:20
问题 I've got this Oracle code structure I'm trying to convert to SQL Server 2008 ( Note: I have used generic names, enclosed column names and table names within square brackets '[]', and done some formatting to make the code more readable) : SELECT [col#1], [col#2], [col#3], ..., [col#n], [LEVEL] FROM (SELECT [col#1], [col#2], [col#3], ..., [col#n] FROM [TABLE_1] WHERE ... ) CONNECT BY PRIOR [col#1] = [col#2] START WITH [col#2] IS NULL ORDER SIBLINGS BY [col#3] What is the SQL Server equivalent

Connect by clause to get the top of hierarchy

拟墨画扇 提交于 2019-12-24 16:31:14
问题 I am facing an issue while using the CONNECT BY clause in Oracle for finding hierarchical data. Let me give an example: A is my parent part which has child part B and B also has a child part C. When I am using the CONNECT BY clause I am able to get all the three levels but I only want the top most level, i.e. A. 回答1: Oracle has a LEVEL pseudocolumn that you can use: SELECT myTable.ID, myTable.ParentID FROM myTable WHERE LEVEL = 1 CONNECT BY PRIOR myTable.ID = myTable.ParentID To find a top

Oracle 'CONNECT BY' Syntax

旧巷老猫 提交于 2019-12-23 02:52:32
问题 This is an offshoot of the following question: Single out duplicates between two result sets As by a comment in that questions, I'm trying to implement my query using Oracle's special 'CONNECT BY' syntax. I'm having trouble finding any (clear) information on how to implement the syntax in my case. My query: SELECT pi.compressed_name, pi.phn, to_char(pi.date_of_birth , 'YYYY/MM/DD') as date_of_birth, to_char(pe.started_on , 'YYYY/MM/DD' ) as medicare_eligibility_start, to_char(pe.ended_on ,

oracle connect by multiple parents

江枫思渺然 提交于 2019-12-22 00:20:07
问题 I am facing an issue using connect by. I have a query through which I retrieve a few columns including these three: ID ParentID ObjectID Now for the same ID and parentID , there are multiple objects associated e.g. ID ParentID ObjectID 1 0 112 1 0 113 2 0 111 2 0 112 3 1 111 4 1 112 I am trying to use connect by but I'm unable to get the result in a proper hierarchy. I need it the way it is showed below. Take an ID - parentID combo, display all rows with that ID-parentID and then all the

NOCYCLE in Postgres

陌路散爱 提交于 2019-12-22 00:16:32
问题 I have a Oracle query with a NOCYCLE clause which I have to translate to Postgres: SELECT FG_ID,CONNECT_BY_ROOT FG_ID as Parent_ID FROM FG t START WITH t.Parent_filter_group_id is null CONNECT BY NOCYCLE PRIOR t.FILTER_GROUP_ID = t.PARENT_FILTER_GROUP_ID I have converted this one with the help of the question and answer in connect_by_root equivalent in postgres as with recursive fg_tree as ( select FG_ID, FG_ID as fg from FG where Parent_filter_group_id is null union all select c.FG_ID, p.fg