Skip to main content
Filter by
Sorted by
Tagged with
0 votes
2 answers
140 views

I am a beginner in SQL. What is the syntax issue with the query shown here? I just needed the random rows to be present n number of times. with recursive cte1 as ( select 1 as idx, company_id, ...
Nidhi's user avatar
  • 21
0 votes
1 answer
89 views

I'm working on Nested Set Hierarchies. I'm using a recursive CTE to build the nested equivalent of adjacency list table. MySQL 8.4 is my platform. -- adjacency list table CREATE TABLE dct_node_adjc ( ...
Felipe Lorenzo's user avatar
1 vote
1 answer
97 views

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, ...
Jonathan Whitaker's user avatar
0 votes
1 answer
109 views

Practicing some SQL from Danny Ma's case studies. Working on number 3, found here. The challenge question that I'm requires an iterative table of payments made during 2020. I'm scaffolding up to my ...
Jacob D'Aurizio's user avatar
1 vote
1 answer
173 views

Consider the following tables: create table WORKS_WITH_BASE_COSTS ( CODE integer not null, BASE_COST decfloat default 0 not null, constraint PK_WORKS_WITH_BASE_COSTS primary key (CODE) ); ...
manlio's user avatar
  • 19.1k
0 votes
1 answer
127 views

In SQL Server, I have a Transactions and a TransactionDetails table. Transactions table has the following columns: TransactionId Amount ProcessedDate TransactionDetailsId TransactionDetails table has ...
Gadir Novruzov's user avatar
1 vote
1 answer
29 views

I have a recursive structure with the following two tables: tree represents a hierarchy of nodes where the top node has parent = NULL. the items can be attached to any of the tree nodes, anywhere in ...
Mark Tyers's user avatar
  • 3,319
2 votes
1 answer
106 views

I'm looking to clean up event data that happens to have "duplicate" rows for a given day. I want to remove rows for a day that have more than one status based on the context of the next day'...
alpacafondue's user avatar
0 votes
1 answer
59 views

The code below is from: https://www.freecodecamp.org/news/mysql-common-table-expressions/ Data: CREATE TABLE categories ( id int, cat_name varchar(100), parent_category_id int DEFAULT NULL ...
Kendo96's user avatar
  • 15
1 vote
1 answer
680 views

I am running this query: WITH RECURSIVE base_record AS ( -- Base case: start from the initial defined term SELECT dt.id AS defined_term_id, dt.name AS term_name, 1 AS depth, ARRAY[...
Sinan Guclu's user avatar
  • 1,087
0 votes
2 answers
92 views

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 ...
PaulH567's user avatar
  • 199
0 votes
0 answers
81 views

I'm having a huge performance issue when I run recursive query. Here is my DB Structure: users: id(index) name 1 A 2 B 3 C 4 D 5 E user_user user_id(index) parent_id(index) 2 1 3 2 4 2 5 4 And this is ...
Jack Richard's user avatar
0 votes
1 answer
107 views

I have following table wherein 2 (can be more) foreign key columns define self-relationship between records of the table. [Hierarchical records in my problem dataset] Id Name Parent1__c Parent2__c ...
Ravi Teli's user avatar
1 vote
1 answer
85 views

I have seen and read many posts on using a recursive CTE to get the hierarchy from a self-related table. I want to get just the root node of an entry in my table. In other words, if I have a suburb ...
Chris Laurie's user avatar
0 votes
2 answers
141 views

I have an SQL-Server 2019 database with 2 tables NODE and EDGE, where NODE consists of two columns ID (int) and NAME (varchar) and EDGE consists of two columns PARENTELEMENTID (int) and CHILDELEMENTID(...
Zyan's user avatar
  • 69
0 votes
2 answers
143 views

I am working with a hierarchy problem where the nodes have two parents and need get only the nodes where both parents are in the result. In the happy world, this query would be perfect WITH RECURSIVE ...
MiguelAngel_LV's user avatar
0 votes
0 answers
38 views

I have a dumb/bad solution to my problem, but I have read the Snowflake docs on recursive CTEs (https://docs.snowflake.com/en/sql-reference/constructs/with and https://docs.snowflake.com/en/user-guide/...
Ali Mustafa's user avatar
0 votes
1 answer
83 views

As part of a T-SQL project on a Microsoft SQL Server, I'm using a recursively unioning CTE to trace a series of child parent relationships through some hierarchical data to pull each individual ...
Wizj619's user avatar
0 votes
1 answer
63 views

I have a table with client_id and parent_clientid. Each client can be a parent and can contain multiple children. I would like to know, for each row, how to get the associated parent and children in a ...
Vijay Ananth's user avatar
2 votes
1 answer
82 views

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 solve by ...
Cal's user avatar
  • 23
1 vote
1 answer
75 views

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 a ...
Arjun M's user avatar
  • 31
0 votes
0 answers
81 views

ID parent_id name is_public ------------------------------------------------ 1 null category 1 0 2 1 category 2 0 3 2 ...
Stanislau Karaliou's user avatar
0 votes
1 answer
140 views

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, ...
Gerzzog's user avatar
  • 309
0 votes
1 answer
135 views

I have an original table in this format WHLO ITNO RESP SUWH 36P F379194 Jasmijn 36E F379194 Mounish 36P W33 F379194 Kneza 36E T44 F379194 Fatin 36E 32P F379194 Mari R55 R55 F379194 Oumaima What i want ...
Mouni's user avatar
  • 1
0 votes
1 answer
1k views

CREATE TABLE `comments` ( `comment_id` int NOT NULL, `user_id` int DEFAULT NULL, `comment` varchar(32) DEFAULT NULL, `post_id` int DEFAULT NULL, `parent_comment_id` int DEFAULT NULL, PRIMARY KEY (`...
Shubham's user avatar
  • 297
-3 votes
1 answer
101 views

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 ...
Carlos's user avatar
  • 57
0 votes
2 answers
109 views

I have a table like below range_from range_end created_on 100 105 2023-01-01 106 110 2023-01-01 106 111 2023-06-01 120 130 2023-01-01 112 130 2023-06-01 I need to clean it to get a most updated ...
HHan's user avatar
  • 3
1 vote
1 answer
121 views

create table the_table ( id integer, root_id integer, parent_id integer, status text, ts timestamp, comment text); insert into the_table values (1, null, null, 'COMPLETE', now()-'92d'::interval, '&...
Nagesh's user avatar
  • 494
1 vote
1 answer
86 views

I have a table that has a structure similar to the following: Id Parent Id Condition 1 0 0 2 1 0 3 0 0 4 3 0 5 3 0 6 3 1 7 6 0 8 6 1 9 8 0 10 9 0 where Condition is a bit that indicates whether the ...
cmur's user avatar
  • 13
0 votes
1 answer
43 views

I have a query from my postgres tables that looks like this: date sku incoming_unit_qty incoming_unit_cost landed_unit_qty 2023-08-01 sku-1 1,000 $3.00 0 2023-08-01 sku-2 2,000 $2.00 0 2023-08-01 sku-...
cohlar's user avatar
  • 81
0 votes
1 answer
87 views

I have a table with stock changes with different countries and different products. The table looks like the following: Date Country Product Variation 2023-10-01 Spain Pen 1 2023-10-01 Germany Pen 1 ...
lukabers's user avatar
  • 189
0 votes
2 answers
121 views

I have an employees table as below : EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID 103 Alexander Hunold AHUNOLD 590.423.4567 38720 ...
Alexis Graham's user avatar
-4 votes
1 answer
520 views

I'm new to snowflake. And I need to know about the recursive view in snowflake. Can someone explain it with an example. And why recursive views are used. Non-Materialized view only I need a really ...
dona's user avatar
  • 15
0 votes
2 answers
248 views

Question I've got a Redshift table which contains hierarchal data by month. I am trying to calculate sum for manager based on people under them but struggling to get the SQL working. Actual data ...
AIViz's user avatar
  • 102
0 votes
1 answer
87 views

I have a temporary table #input which holds an ID and a calculation date cdate. I have another temporary table #service which holds a service record for each ID. The field ‘countable’ on the #service ...
vinstra_82's user avatar
1 vote
1 answer
1k views

I am not sure if this has been asked before but I have searched across different forums and haven't found the exact answer. Should we always initialize the word RECURSIVE to the first CTE (even though ...
Stryken_03's user avatar
1 vote
2 answers
343 views

I have a recursive SQL query that traverses a tree-like structure using a table variable. The query works correctly, but I'm facing performance issues. The idea to pull hierarchical parents till the ...
minato namikaze's user avatar
0 votes
0 answers
66 views

I am working on a SQL Server 2016 database where I have recipes and ingredients stored in separate tables. The relationship between recipes and ingredients is stored in a junction table. I am using a ...
Santiago Jose Gianotti's user avatar
0 votes
1 answer
528 views

Using PostgreSQL 14, I'm working on a table workplaces which models a tree of workplaces. Besides attributes like country_code, each workplace identifies its parent workplace via a parent_id foreign ...
Frerich Raabe's user avatar
0 votes
0 answers
39 views

I'm trying to print from a db the categories in a hierarchy order. I have developed a mysql code that sort of works in dbfiddle (https://dbfiddle.uk/_oUW-eW_), but I am not able to make it run in PHP. ...
Andrealuigi's user avatar
0 votes
2 answers
434 views

I am trying to use a recursive CTE to combine multiple calls to a table valued function. I have a fiddle at: https://dbfiddle.uk/kktqHivz I have a table called sales: create table sales ( date ...
Manngo's user avatar
  • 17k
-1 votes
1 answer
56 views

Problem I have two tables. employee and salary. For the employee table I have employee_id and supervisor_id. employee_id supervisor_id 0 5 1 5 2 5 3 6 4 6 5 7 6 8 7 NULL 8 NULL For the salary table I ...
mu_sa's user avatar
  • 2,745
0 votes
2 answers
629 views

I am trying to design a RDBM model for a family tree using SQL Server and currently I have the 3 tables that looks somewhat as follows Members - Stores basic details of members of the family. ---------...
Ranjith R Shenoy's user avatar
1 vote
1 answer
90 views

I am programming in Visual Studio, but I need to perform validation on mySQL (v8.0.28) table and I guess it would be faster if it will be performed as procedure on server. Unfortunatelly, my MySQL ...
MadToolmaker's user avatar
0 votes
1 answer
103 views

Basically I have a table of membership dates and status changes and I want to create a rolling count of each number of members by status for each date like: And I want to output it like: Not really ...
Benzo's user avatar
  • 13
0 votes
1 answer
21 views

I am trying to find a group account and populate the aggregation of its child accounts QTY and Market value using CTE and Recursive CTE.. it gives me the correct result 3 times.. Not sure what i am ...
Mohan's user avatar
  • 61
0 votes
1 answer
97 views

I have below source table - TEST_TAB DP_AD_ACCT_NBR DP_AD_CCY_CDE DP_AD_CURR_BAL DP_AD_LST_MDFSN_DATE 10001 REL123 100 2014-11-18 10001 REL123 174 2018-03-04 10001 REL123 145 2022-12-21 10001 REL123 ...
user avatar
2 votes
2 answers
529 views

I would like to query hierarchy results ordered by depth first without the use of SQL's heiarchyid built in function. Essentially, I am hoping to accomplish the depth ordering without any fancy ...
DizzleBeans's user avatar
0 votes
0 answers
105 views

supose we have the next table: table example and what i need is: frst iteration: calculate the moving average 5 days before the last day including the last day = (2+1+2+3+4)/5 = 2.4 and "save&...
Pantuflas's user avatar
2 votes
1 answer
2k views

I would like to use string_agg(column_name,',') on some IDs in a column from a SQL result set. I would be grouping by a single key, but also want to make sure each grouped set results in n rows being ...
Coldchain9's user avatar
  • 1,767