2,104 questions
1 vote
1 answer
117 views
Postgres Recursive Query Behavior
I have a table test with two columns, each referencing the other ID1 ID2 2 1 3 2 4 3 5 4 Given an id, I need to traverse the chain to return all the rows traversing the chain. Below is the query I ...
4 votes
1 answer
141 views
How to include a recursive query in the main query?
I have a database in SQLite with these tables and columns: Products: id, name, number, price, category_id. Orders: id, client_id, datetime, sum. OrderProducts: order_id, product_id, product_count. ...
0 votes
0 answers
36 views
recursive sum of totals by org and descendants in redshift
I have a table like this: total alert group_id hlevel full_path parent_id root_group_id 5100FFFF-60B6-D5CD-FCCD-A8A3E03F0000 1 BizA\DivA 5100FFFF-60B6-D5CD-BFBA-A8A3E03F0000 5100FFFF-60B6-D5CD-FCCD-...
0 votes
4 answers
135 views
Recursive CTE to insert an entry for every day
Consider the following: IF OBJECT_ID('tempdb..#TetstData') IS NOT NULL DROP TABLE #TetstData CREATE TABLE #TetstData ( Id INT NOT NULL, PurchaseDate DATE NOT NULL, DepreciationRate ...
-3 votes
1 answer
64 views
How to write recursive query for path generation and cycle detection?
I'm working with hierarchical tree data in DolphinDB and need to solve two specific programming challenges: Generate full paths (concatenated IDs and names) for all nodes, including infinite-level ...
0 votes
1 answer
67 views
Recursive Query to generate dates not working
I am trying to generate a series of dates by RECURSION in BigQuery. Unfortunately, the solution DOESN'T work !! Can someone please explain where I might be going wrong ?? Note: I understand that ...
0 votes
2 answers
115 views
Nested Loop in SQL in BigQuery
I need to calculate few metrics for a period of days. The requirement is - For a given day, calculate the metrics based on the past 7 days. I need to output the metrics for every day for the past 2 ...
3 votes
2 answers
152 views
Recursive query for nomenclature like table with parent contains sum of all cost from children
I have a table like this: COMPOSANT COMPOSE QTE PA COST LEVEL PARENT1 CHILD1 24 0 PARENT1 CHILD2 2 0 CHILD1 CHILD11 10 1 CHILD1 CHILD12 4 3 12 1 CHILD11 CHILD111 100 1 100 2 CHILD2 CHILD21 5 10 50 1 ...
1 vote
1 answer
51 views
Traversing graph using recursive CTE - using "array" to store visited vertices
I'm studying graph traversal using recursive CTEs (learnSQL course). The question asks about visiting every city from a starting city. They use a "path" string built up from appended city ...
0 votes
1 answer
104 views
ORACLE Query for all connected records
I have a joining table that performs a two-way binding using a single record. In the example below, the record with id=8 is linked to the record with id=4, and the record with id=4 is linked to the ...
-5 votes
1 answer
68 views
Trouble with recursive query in redshift
Considering following test data: CREATE TABLE products_su ( country varchar(2), intprd varchar(20), period date, su int ); INSERT INTO products_su (country, intprd, "period&...
2 votes
4 answers
157 views
Recursive query to figure out record which creates circular dependency
I have a postgress table incoming_records which contains 2 column supervisor_id, emp_id create table incoming_records(supervisor_id,emp_id)as values (null,01) --top level resources with blank ...
1 vote
2 answers
115 views
Multiple recurrence within redshift/postgres recursive query
I'm seeking help with including deeper recurrence then last row with recursive query. Source data: CREATE TABLE products_su(country, intprd, "period", su)AS VALUES ('GL', 'Medicine', '2019-...
1 vote
1 answer
71 views
oracle query to loop through multiple records and provide the results [closed]
oracle query to loop through multiple records and provide the results Please help qrite an oracle query to achieve above results. input data ID ABRV NXTFILL DAYSOUT_INT DAYSOVER_INT TIME 123 abc null ...
1 vote
1 answer
97 views
Recursive CTE with cycle detection using path array
I have a recursive CTE definition (graph) in Postgres that involves cycle detection: fiddle CREATE TABLE relationships ( subject_type, subject_id, subject_relation, resource_type, ...