2,068
questions
0
votes
1
answer
50
views
Identifying Overlapping Appointments with One Non-Overbooked Occurrence
Scenario:
Appointments are made with start and end times. Appointments are allowed to overlap, but for reporting purposes, we need to know when there are overlapping appointments (called overbooking) ...
0
votes
2
answers
67
views
Suppress Duplicates in SQL Server Recursive Query
I've got a data structure where a record represents a person. A person can have a relationship to another person. There are different types of relationship so it's possible that there can be multiple ...
0
votes
0
answers
23
views
Jpql recursive query problem resolving entity name
I'm working with SpringBoot 3.2.5 and Hibernate 6.4.4 and I want to create a jpql recursive query. I have the following query
@Query("""
WITH modules AS (
SELECT ...
0
votes
2
answers
56
views
Generate rows for an INSERT using recursion
I need to insert data into new table person_department using recursion.
My tables for now:
person
id group_id
800 10
805 21
department
id name group_id parent_id
1 ABC ...
0
votes
1
answer
57
views
Recursive SQL query with links in PostgreSQL (migration from Oracle)
I have a table called NodeHierarchy
id
name
parentId
linkedTargetId
1
A
null
null
2
B
1
null
3
C
2
null
4
D
2
null
5
E
3
null
6
F
4
null
7
G
3
null
8
H
6
3
9
I
6
null
in Oracle i can use ...
0
votes
1
answer
44
views
CONNECT_BY_ROOT Inside of a CONNECT_BY_ROOT
I'm trying to combine two CONNECT_BY_ROOT queries. They work well individually. I've been trying to combine them such that one is a subquery inside the other, but I'm falling short.
Query 1 - ...
1
vote
2
answers
42
views
Simulate recursive formula
I'm working on HIVE.
I have the following data:
Date
WholeBudget
Target PocketA
PocketA
PocketB
2024-01-01
60
75%
45
15
2024-01-02
80
75%
60
20
2024-01-03
100
50%
60
40
2024-01-04
110
50%
60
50
...
0
votes
1
answer
70
views
Complex BigQuery recursive CTE use case that joins on non-unique key and also unions at the same time
I have a complex (but highly interesting!) use case for BigQuery recursive CTE. I understand how to solve it conceptually but after hours of trying, I just can't get my head around exactly how to do ...
0
votes
1
answer
60
views
Get all hierarchy in SQL Server
I have a table like this:
ID_employee
ID_Manager
1
1
2
1
3
1
4
2
5
3
6
5
7
5
8
5
(1 is a boss)
What I would like is a result like:
ID_employee
ID_Manager
8
5
8
3
8
1
7
5
7
3
7
1
6
5
...
1
vote
3
answers
67
views
How can I calculate this conditional monthly limit?
In May client P003 had 600 of buy_amt (sum of sales in that period) and 1000 transfer_amt. I want to calculate the remaining limit (buy_amt - transfer_amt) but starting from top to bottom and the ...
0
votes
1
answer
99
views
Get sibling and parents with recursive SQL Server query
I have this table
Id
ParentId
1
NULL
2
1
3
1
4
NULL
5
4
6
8
7
9
Each child (Id) can have only one parent.
How to retrieve parents and sibling for a given child Id, it means:
SELECT `Here the ...
1
vote
1
answer
98
views
How to rewrite Oracle sql's hierarchical query to polars?
In Oracle I have the following hierarchical sql:
with prod as (select 10 id,'1008' code from dual union all
select 11 id,'1582' code from dual union all
select 12 id,'1583' ...
0
votes
1
answer
44
views
Combine parent id and all child ids in an array in a single row using recursive cte
I have a table pr with two columns:
stg source id, parent id
125, 124
126, 125
127, 125
128, 127
what I want a final result as:
parent id, stg_source_ids
124, [125, 126, 127, 128]
as my final row ...
0
votes
1
answer
30
views
SQL assign a value from a column in table A until all the values of a column in table B are populated
I have a table box as depicted below.
box_name
---------
box1
box2
box3
box4
box5
box6
box7
box8
box9
box10
And another table color as shown below
color
------
red
blue
green
My objective is to ...
-1
votes
1
answer
112
views
Recursive CTE and performance issue when anchor member is a large table
I have made some edits so that the post is clearer.
I have a large table with data like below.
The goal is to be able to retrieve the original ID and location associated with the original ID given ...
1
vote
0
answers
89
views
BIG Query recursive CTE or other possible solution
I have a table with 10 million unique Product_ID. This Unique Ids are being tested by the hr and the metric has a [good : -1, neutral : 0, bad : 1], I call this column hr_status. I want to develop a ...
-1
votes
3
answers
79
views
Conditional recursive query in SQL Server
I have these 2 tables:
TABLE 1
Id
Shortname
ParentId
C1
Child1
P1
P1
Parent1
GP1
GP1
GrandParent1
NULL
C2
Child2
P2
P2
Parent2
GP1
TABLE 2
Id
Setting
GP1
5
C2
1
The logic is the following: ...
1
vote
1
answer
65
views
Oracle Connect By hierarchy query returns top level parent but child part is null
I have a CONNECT BY hierarchal query that starts with a known child part and returns the top level parent(s). It runs quickly and works great except for one thing: it returns null values for the child ...
0
votes
1
answer
51
views
Oracle help using Connect By Root to return assembly top level parent
I'm trying to use CONNECT BY ROOT to do a recursive query that returns the top-level parent of an assembly part. My query so far is only able to return the parent one level above. I created a test ...
0
votes
0
answers
18
views
Many to Many Recursive Relationship
I have a database with a single table, with a Many to Many Recursive Relatopnship.
Need to: "Associate/join" records and also be able to delete the joins.
I've know basic sql: insert, delete,...
0
votes
1
answer
44
views
Recursive count query in PostgreSQL
I have a website on which users can place comments on nodes and also comment as a reply to other comments without a depth limit. The table structure of the comments table is as follows (simplified):
...
-3
votes
1
answer
54
views
For each employee need to get the sum of values based on their start date every month
I have two tables.
Table 1:
emp
startdate
010
15/02/2022
011
21/05/2022
012
04/012/2022
I need to have additional columns :startdate1 and enddate
which should look like:
emp
startdate
startdate1
...
0
votes
1
answer
46
views
MariaDB - Recursive Query with condition on last recursion level
given a MariaDB database with information about S/MIME certificates and the following database structure:
Table: cm_certificates
cm_id
cm_not_after
cm_issuer
cm_subject
cm_store_name
1
2028-09-20 08:...
1
vote
1
answer
105
views
Clickhouse generate X rows of Y random numbers in an array
I would like to extend the below to return multiple rows, where each row has a different array of random values
with base as (
-- makes a random number 0 to 50, adds up to 10 into an array
...
-2
votes
4
answers
124
views
Recursive query to replace null values [closed]
With the following table, I need to make a query to replace the null values of “time” (number of minutes, integer) by a value consistent with the preceding and following values, with partitioning by “...
0
votes
1
answer
41
views
How it works a Recursive MySQL Query
I'm working on a mini project for warehouse management, and I need to manage the available quantity of items. Sometimes articles can be composed (made up of one or more different articles), which in ...
0
votes
0
answers
68
views
BigQuery SQL query for traversing an undirected cyclic graph and returning all vertices found
I have an edges table in my Bigquery database that represents the edges of a directed cyclic graph, with two columns: (node_from, node_to).
Given a set of initial nodes (initial_node), I'd like to be ...
0
votes
1
answer
50
views
how to write SQL query to loop across multiple tables or maybe use recursive query
When I have 1 item in tmp_lookup my results are fine. When I have 1 + item in lookup table the results are not as expected, there are some double records. 'Tmp_pat1' table creates record for ...
-1
votes
1
answer
46
views
Extraction of Parents by hierarchy for employees using Azure Synapse Analytics
I am looking for a solution for the below situation:
I have to extract all the managers (by hierarchy) for some employees that i receive in the flow (we have a file that contains all the information ...
-2
votes
1
answer
67
views
Find which stores have been transferred to which store that is currently active
I have a stores table which takes in storeid, isactive and transferstoreid.
id= the id of the store
isactive= whether the store (id column) is active or not
transferstoreid = the new store id to which ...
0
votes
0
answers
56
views
recursive query postgresql not running recursively
The below query runs and works without errors. However, it is not running recursively. Can someone point me in the right direction on why this might be?
with recursive parentlots as(
with
...
1
vote
1
answer
65
views
Syntax error at or near "perform" on Recursive Query
I'm using a stored procedure to get the total query execution time in PgAdmin.
Based on some readings, I tried the following:
DO $proc$
DECLARE
StartTime timestamptz;
EndTime timestamptz;
Delta ...
1
vote
1
answer
145
views
How to create tree structure from html element?
this is my element in my vue2 application:
<div class="child-elements-container draggable-container">
<div>
<div entity-type="entitytype1" type="...
1
vote
0
answers
143
views
VBA to create Multi level Bill of Material from Single Level Bill Of Material
'I am trying to convert single level bill of material to multi level bill of material for multiple Finish goods, get some codes and
'this working, however when i add large data set in Sheet1 and list ...
2
votes
1
answer
70
views
clean ways to perform calculations with values sourced from nested groups of varying depths?
I would like to use the below tables to calculate z:
item
value
a
6
b
8
group
source_item
weighting
x
a
1
x
b
0.25
y
a
1
group
source_group
weighting
y
x
0.5
z
x
1
z
y
1
As a human, I'd ...
0
votes
1
answer
113
views
CTE query in snowflake to traverse the hierarchy
I have an emp table that has data like below in Snowflake. I need to add a column with the col name ED_ID will will point to the immediate ED_id in the hierarchy. If there is no ED in the employee's ...
0
votes
1
answer
43
views
How can I create a recursive CTE query to get root parent_id SQL
I have a table like this
Post
id: text pk not null
content: text not null
author_id: text fk references User(id) not null
parent_id: text fk references Post(id)
My question is, how can I get every ...
0
votes
1
answer
60
views
hierarchy table to open all connections level into rows - snowflake
I have an hierarchy table that includes connections between entities.
for example:
entity_id
entity_type
resource_id
resource_type
1
X
2
Y
2
Y
3
Y
3
Y
4
Z
what i would like to get in the end:
...
1
vote
1
answer
66
views
recursive CTE with two child column
basically I have a audit table like the following.
JOB_NO
DEPENDANT_JOB_NO
DEPENDANT_SUB_JOB_NO
Job_198
Job_551
BDP2_Sjob_48
Job_24
Job_551
BDP2_Sjob_23
BIL_Job_10
Job_5
Sjob_6
I need to develop ...
0
votes
1
answer
103
views
Optimise recursive CTE or rewrite to PL/pgSQL LOOP
I've got a procedure with recursion in Postgres 13 version.
It makes orgstructure from Vice to simple employer
with recursive relations_recurs(
pos_id, boss_pos_id, level_num, link_type, ...
-2
votes
1
answer
108
views
Recursive CTE to generate all combinations sub groups within a group
I am trying produce an aggregated result for all possible combinations of rows linked by one column (package_id) but where another column (package_item_id) does not match.
I have a derived table ...
-3
votes
1
answer
84
views
Parent Child table with "N" number of levels [closed]
This query:
SELECT pcn.id,
pcn.config_id,
pcnc.nombre_nivel,
pcnc.orden_nivel,
pcn.nivel_padre_id,
pcnc.empresa_id,
pcnc.proyecto_id,
pcnc.activo AS ...
1
vote
1
answer
120
views
Recursive Queries with Window functions
So, I have a table:
DATE STORE PRODUCT
01.01.2020 Store1 Product1
01.01.2020 Store1 Product2
01.01.2020 Store1 Product3
01.01.2020 Store1 Product4
01.02.2020 Store1 Product5
01.02....
0
votes
1
answer
80
views
Oracle | Find All parent recursively and return results in comma seperated
I have the following table in an oracle:
P_C_REL (Child , Parent ,Ownership)
Child
Parent
Ownership
41203134
10151091
100
10250181
40001104
30
40856701
40109963
100
10159060
40001104
100
...
1
vote
0
answers
39
views
Mysql - hierarchical recursive query [duplicate]
I have a MySQL table which is as follows:
Id
Name
Parent_id
1
Admin
2
2
Admin2
3
3
SuperAdmin
0
31
User1
1
32
User2
31
33
User3
32
I use mysql query:
select id,
username,
...
0
votes
0
answers
183
views
Calculating a value in SQL using previous row's values and then using current row value for future calculations
In SQL Server, I have to perform calculations on the following table:
Row#
Period_begin_dt
Period_end_dt
Amount
Period_Status
Time_Period
1
2023-07-01
2023-09-30
0
Delinq
Quarterly
2
2023-04-01
...
0
votes
1
answer
188
views
How to do SQL recursive logic
I have this sample dataset like this ;
acctid
payseq
totalamount
acctnum
expectprice
payorder
aac1
99
1000.00
1111aa
800.00
1
aac1
99
1000.00
1111bb
800.00
2
aac1
99
1000.00
1111cc
800.00
3
aac1
...
-1
votes
1
answer
113
views
sqlite recursive common table expression using pragma foreign_key_list
I'm trying to enumerate all parent tables and their parent tables for a given table.
the following sqlite script sets up a parent>child>grandchild hierarchy, does select pragma_foreign_key_list ...
0
votes
2
answers
186
views
Update chain of rows in which each row will affect next one through a computed column
In a banking DB we want to hold the transactions and remainder amount of accounts after each transaction in a table named 'Operation' like this:
CREATE TABLE Operation (
Id int PRIMARY KEY,
...
-4
votes
3
answers
183
views
Sort multiple lines based on one line [closed]
I've a file with following lines:
Name: Karl
Born: 2003-07-06 17:21:36.964
State: Germany
Hobby: Videogames
Name: Albert
Born: 2003-07-05 18:16:19.369
State: UK
Hobby: Soccer
Name: Mark
Born: 2003-...