Skip to content
Advertisement

Tag: recursion

Sql server Balance Table Update Recursive

I Have a SQL Server database with a table named Balance The table: Id Date IN OUT Balance 3345312 2022-08-07 100 50 250 5435245 2022-08-06 50 50 200 4353451 2022-08-05 0 100 200 5762454 2022-08-04 20 100 300 7634523 2022-08-03 400 100 380 5623456 2022-08-02 100 20 80 4524354 2022-08-01 0 0 0 Id = Unique Identifier Date = Balance

Recursively Conditionally get parent Id

I have two tables: Budget Line and Expense. They are structured in such a way that an expense must have either a parent record in the budget line table, or a parent record in the expense table. I need to select all child-most expenses for each budget line. For example – BudgetLine: Id Description 1 TEST123 2 OTHERTEST Expense: Id

Postgres – How to achieve UNION behaviour with UNION ALL?

I have a table with parent and child ids. Each parent can have multiple children and each child can have multiple children again. The data looks like this. I’d like to find all children. I can use a recursive cte with a UNION ALL. This gives me the result I’d like to achieve. However I’d like to include the depth

Cycle detected while executing recursive query

I am using CTE recursive query to get below output but don’t know why it is throwing “cycle detected while executing recursive WITH query”. Can anyone please tell me where is wrong with my query? my query: SELECT order_id, product_id, quantity FROM cte; table/data script: Answer In the recursive member you are currently only joining on a.product_id = b.product_id, rather

Follow the connections : recursive query

i have two columns of numbers. the goal is starting from a number f.e. 55, to extract all ‘connected’ numbers (starting with any of those numbers, should yield the same result) in this case all numbers shown here : 55,56,35,69,60,22,47,2,26 I use the following query : but I get back only those back : 55,56,35,69,60,22,47 I think using this will

Advertisement