connect-by

Does PostgreSQL have a pseudo-column like “LEVEL” in Oracle?

一曲冷凌霜 提交于 2019-12-19 15:04:52
问题 Does PostgreSQL have a pseudo-column like "LEVEL" in Oracle? If not, then how can we create a column similar to "LEVEL"? 回答1: Postgres does not have hierarchical queries. No CONNECT BY , therefore also no LEVEL . The additional module tablefunc provides the function connectby() doing almost the same. See: What is the equivalent PostgreSQL syntax to Oracle's CONNECT BY ... START WITH? Or you can do similar things with a standard recursive CTE and a level column that's incremented with every

Does PostgreSQL have a pseudo-column like “LEVEL” in Oracle?

做~自己de王妃 提交于 2019-12-19 15:00:01
问题 Does PostgreSQL have a pseudo-column like "LEVEL" in Oracle? If not, then how can we create a column similar to "LEVEL"? 回答1: Postgres does not have hierarchical queries. No CONNECT BY , therefore also no LEVEL . The additional module tablefunc provides the function connectby() doing almost the same. See: What is the equivalent PostgreSQL syntax to Oracle's CONNECT BY ... START WITH? Or you can do similar things with a standard recursive CTE and a level column that's incremented with every

Is there a way to detect a cycle in Hierarchical Queries in SQL Server?

半腔热情 提交于 2019-12-14 03:52:15
问题 In Oracle, we can use the function CONNECT_BY_ISCYCLE to detect a cycle in Hierarchical Queries. I try to do the same in SQL Server. Is there a way to do this? Thanks a lot! 回答1: Concatenate the records IDs / build a bitmap based on ROW_NUMBERs of the records and verify each new record against the list/bitmap create table t (id int,pid int) insert into t values (1,3),(2,1),(3,2) List Identify Cycles with cte (id,pid,list,is_cycle) as ( select id,pid,',' + cast (id as varchar(max)) + ',',0

hierarchy query (connect by clause)

↘锁芯ラ 提交于 2019-12-12 02:44:54
问题 I'm trying to writte a query using connect by clause but I can't handle with that. Generally I have table: CREATE TABLE "TESTOWA" ( "ACCOUNT" VARCHAR2(20 BYTE), "PARENT" VARCHAR2(20 BYTE), "PAYMENT" VARCHAR2(20 BYTE) ); Insert into TESTOWA (ACCOUNT,PARENT,PAYMENT) values ('5436','5436','1'); Insert into TESTOWA (ACCOUNT,PARENT,PAYMENT) values ('4576','3457',null); Insert into TESTOWA (ACCOUNT,PARENT,PAYMENT) values ('5763','5686','1'); Insert into TESTOWA (ACCOUNT,PARENT,PAYMENT) values (

Oracle to Derby - ConnectBy and Start With Equivalent in Derby

守給你的承諾、 提交于 2019-12-11 18:52:29
问题 The following Query1 is fine with Oracle. I want the same functionality to be carried out in Derby. I got the Query2, as one of the suggestion to be followed here. But still that is throwing the Error1. Please somebody help me out to get rid of this. What should I do? Query1: Select f.folder_id, f.identifier From FOLDER f, STOREENT se Where f.type = 'AttributeFolder' And se.storeent_id = f.storeent_id And se.identifier = 'Global_CAS' And f.identifier = 10051 connect by prior f.folder_id = f

Oracle, Connect By rownum

自作多情 提交于 2019-12-11 13:50:43
问题 I tried to find some informations about connect by "engine". I found this post: Confusion with Oracle CONNECT BY User krokodilko answered and says: The analyze of the last query: select level from dual connect by rownum<10; I leave to you as a homework assignment. So i tried to do exactly as described to query Select rownum from dual connect by rownum < 3 And here's my "work": CREATE TABLE step1 AS SELECT 1 "LEVEL" FROM dual; SELECT * FROM step1; create table step2 as SELECT 2 "LEVEL" from

“Connect By” to generate rows from multiple delimited string

和自甴很熟 提交于 2019-12-11 11:58:16
问题 we can use "Connect By" to generate rows from a delimited string in oracle. like: SELECT Rn ,Regexp_Substr(data, '[^,]+', 1, LEVEL) Data FROM (SELECT 1 Rn ,'id:a,val:b,desc:c' data FROM Dual) Idata CONNECT BY Regexp_Substr(data, '[^,]+', 1, LEVEL) IS NOT NULL I want to use the inner query as a union all of a few more records. Something like: SELECT Rn ,Regexp_Substr(data, '[^,]+', 1, LEVEL) Data FROM (SELECT 1 Rn ,'id:a,val:b,desc:c' data FROM Dual UNION ALL SELECT 2 Rn ,'id:a2,val:b2,desc:c2

Oracle 10g PL/SQL Connect By Prior returning Child and Parent on same row

你。 提交于 2019-12-11 07:46:52
问题 Table1: Child Parent a Bob Chris 2 Chris Kate 1 Shane Lana 3 Nala Bob 4 Table2: b Talent 1 'something' 2 'nothing' 3 'something' 4 'nothing' SELECT Child FROM Table1 INNER JOIN Table2 ON (Table1.a = Table2.b) WHERE Table2.Talent = 'something' connect by prior Table1.Child = Table1.Parent This code returns rows of parents Chris If the "Where" clause was not included, the code would return: Bob Chris Kate Chris Kate Shane Lana etc What I want to return is the following in a row, not in columns:

Not getting full series multiplication (product) in CONNECT-BY query

倾然丶 夕夏残阳落幕 提交于 2019-12-11 03:52:37
问题 I have a CONNECT BY query that I am not getting desired results from. The final sub-query and query are supposed to produce the product of multiplying a string of percentages together. It starts with a table of retained percentages (PCT) from year to year. As the query progresses, it's supposed to take the PCT from the first year and multiply it by the PCT from the next year and so on until it reaches the desired depth. The effect is supposed to be like multiplying down the diagonal in a

Mixing together Connect by, inner join and sum with Oracle

橙三吉。 提交于 2019-12-07 08:17:03
问题 I need help with a oracle query. Here is my setup: I have 2 tables called respectively "tasks" and "timesheets". The "tasks" table is a recursive one, that way each task can have multiple subtasks. Each timesheet is associated with a task (not necessarily the "root" task) and contains the number of hours worked on it. Example: Tasks id:1 | name: Task A | parent_id: NULL id:2 | name: Task A1 | parent_id: 1 id:3 | name: Task A1.1 | parent_id: 2 id:4 | name: Task B | parent_id: NULL id:5 | name: