2,095 questions
4
votes
1
answer
115
views
How to aggregate hierarchical data efficiently in Django without causing N+1 queries?
I’m working with a hierarchical model structure in Django, where each level can represent a region, district, or village. The structure looks like this:
class Location(models.Model):
name = models....
-2
votes
1
answer
74
views
MySQL order by id but prioritize an empty value of a certain column
Mainly, I want to order the ids in descending direction but also, how can I sort parent product/items (the ones with empty ean) first and their child rows below them?
Here's an example data from the ...
1
vote
1
answer
108
views
Build the JSON Hierarchy structure using raw response
I am struggling to build the JSON hierarchy structure from the raw response JSON which I am getting from other API.
I want to generate a hierarchy structure from raw JSON Response on the basis of ...
0
votes
0
answers
51
views
Hierarchy Transformation/Looping using Pyspark, Python
I have some SAS code and need to convert it to PySpark code.
Hierarchical SAS Code Part (1)
if cc1 = 1 then do i = 2, 3; cc(i) = 0; end;
if cc2 = 1 then do i = 3; cc(i) = 0; end;
Basically, this code ...
-2
votes
2
answers
163
views
Query to find all members of multi level many to many relationships and also the top most member of the hierarchy
Multiple student can go to 1 teacher, but 1 student can't go to multiple teacher. There is no limit of level in this teacher student hierarchy.
How using a single SQL query in SQL Server we can get ...
-2
votes
2
answers
76
views
Inserting root id to all its children
I have a table with hierarchy v_name
**id: name: child_id**
1000 abc null
1001 bac 1000
1002 cab 1001
1003 lop 1001
1004 jui null
1005 njj 1004
Now we are ...
2
votes
5
answers
105
views
Dropping grouped rows based on a certain hierarchical column
Suppose I have this pandas dataset:
ID
Question Code
1
Q01
1
Q01-1
1
Q02
2
Q01
2
Q02
2
Q02-1
2
Q02-1-1
2
Q02-2
I want to remove the rows based on certain hierarchical conditions between the values of ...
-1
votes
1
answer
113
views
Path table to HTML treeview in SQL Server
I have a SQL Server table with these rows:
id
path
1
a
2
a/b
3
a/b/c
4
a/b/c/d
5
a/b/c/e
6
a/b/f
7
a/b/f/g
8
a/h
9
a/h/i
10
a/h/j
etc...
I need a T-SQL script witch generate a treeview with ul, li tag ...
1
vote
1
answer
87
views
fixed-effect model matrix is rank deficient so dropping 5 columns / coefficients (lme4 package) after grouping age into four categories
This question appears to be a duplicate, I am however unable to resolve my case by looking at the existing suggestions on my model. I am trying to fit the three-level random intercept model. The idea ...
0
votes
1
answer
100
views
How to introduce a random error within a Bayesian count model?
I am trying to model counts distribute across groups in JAGS, but I need to add a random effect for the presence of multiple counts from the same individual.
The model is taken from here
enter link ...
0
votes
0
answers
76
views
Creating Node-Specific Tree Diagrams with Pyvis or Alternative Libraries?
I am working on generating hierarchical graphs using Pyvis. In my case, the nodes are not all connected to each other, so I would like to implement a dropdown menu that allows selecting a node by name....
1
vote
1
answer
56
views
How to use recursive function for product transition? [closed]
In Oracle SQL, I have a product transition table named kit_transition_mapping that is a slowly changing dimension and an orders table. For an order_no based on the order_date, I need to utilize the ...
1
vote
1
answer
29
views
MySQL Recursive CTE to retrieve all Attached Nodes of a Table
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 ...
0
votes
0
answers
20
views
algorithm to validate complex json data in a table which stores json key value pairs in column ,use it in another table which stores parent child data
1.extract all the key value pairs - suggest option which can be reused (temp table,CTE,or more suitable)
2.write a query which takes one key value at a time and searches for the value in another table ...
0
votes
3
answers
79
views
Transpose Hierarchical Table based on leaf nodes with roots as first column
This is similar to this one here. The difference is I want to display the roots in the first column (to the left)
I have a hierarchical table categories as follows:
id
name
parent_id
1
Accommodation
...
0
votes
2
answers
74
views
Transpose Hierarchical Table based on leaf nodes with nodes as first column
I have a hierarchical table categories as follows:
id
name
parent_id
1
Accommodation
null
2
Transport
null
3
Utility
1
4
Maintenance
1
5
Private
2
6
Public
2
7
Electricity
3
8
Gas
3
9
Internet
3
10
...
1
vote
3
answers
106
views
Oracle SQL hierarchical query data accumulation
I need to accumulate data in hierarchical query like this:
select
id,
prior id as parent_id,
count * prior count --need to be accumulated through whole hierarchy like sys_connect_by_path
from ...
0
votes
1
answer
131
views
how to store tree structure in database?
I want to save and restore a tree structure in mysql database ?
I try to save it by adding "parent_id" field to reference the id of parent row.
the parent but it can reference to each other ...
0
votes
1
answer
366
views
How to make hierarchical view with nested child views in Swiftui
How to make this using Swiftui:
I tried to make this design in swiftui and it is resembling as well but i don't think this approach is a cleaner way. I am attaching my code below.
struct NewShapeView:...
2
votes
2
answers
75
views
Creating data.table rows for all levels of groups/supersets in a hierarchy
I have a taxonomic dataset that looks like the following:
sample_table <- data.table(Phylum = c("Arthropoda", "Arthropoda", "Arthropoda", "Arthropoda"),
...
0
votes
1
answer
73
views
Map table to exactly one of three
I have the following tables (taken out of a larger schema). It worked well for the intitial purpose (i.e., optionally map only the parent category to the wallets_balance_history table).
Now, there is ...
0
votes
1
answer
136
views
Flag all bosses in meeting based on org tree
My task is to flag "boss level" participants in data collected from meetings, based on a given org chart.
In other words, it needs to identify the highest ranked individual(s) within the ...
0
votes
1
answer
52
views
Extrapolating self-referencing keys from a hierarchy column
I'm working with a dataset in MySQL that includes a hierarchy column with formats like:
1
1.A
1.A.1
1.A.1.a
1.A.1.b
1.A.2
1.A.2.a
1.B.1
1.B.1.a
2
2.A
...
I'd like to build a table with a self-...
0
votes
1
answer
84
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 - ...
0
votes
1
answer
463
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
0
answers
138
views
display hierarchical data with MariaDB query?
I am trying to display hierarchical data with MariaDB (V.10.4.32-MariaDB) query, to show relationships,( like list of recipes, corporate org chart or program hierarchy). I can do some manipulation in ...
4
votes
1
answer
163
views
Bottom-up tree structure cumulative sum
CREATE TABLE Emissions (
entityId VARCHAR(512),
parentId VARCHAR(512),
emission DECIMAL,
percentContribution VARCHAR(512)
);
INSERT INTO Emissions (entityId, parentId, ...
0
votes
2
answers
68
views
Weighted hierarchical cumulative sum
I don't know if I'm using the correct terminology, but I'm trying to find the cumulative sum of each node in a tree structure, but the children node only contribute a percentage of its cumulative sum ...
0
votes
0
answers
58
views
SQL for hierarchical cumulative sum, but with cumulative sum of child node modified before used to calculate parent's cumsum
entityId
parentId
percentContribution
emission
emission_locationbased
emission_marketbased
cumsum_locationbased
cumsum_marketbased
E1
60
30
60
70
E2
E1
80
20
30
40
E3
E2
80
10
20
10
20
This is a ...
1
vote
1
answer
129
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
79
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 ...
1
vote
1
answer
74
views
Algorithm for compound fractions
I have a set of N chemical compounds enumerated 1, 2,..., N. For each compound, I have the fraction of each of its constituents, "A", "B", and so on. Compounds can also contain ...
0
votes
0
answers
39
views
How to connect 20 same kind of tables in PowerBI?
I have excel workbook containing budget data on yearly basis. The budget is divided into certain categories and these categories are following a hierarchy. The columns of the sheets are as follows.
...
0
votes
1
answer
271
views
Calculating robust SEs following full matching (MatchIt) with mixed-effect models (lme4)
I am attempting to estimate a treatment effect for a study that features both (a) hierarchical data (students within classrooms; implemented with lme4) and (b) matching between treatment and control ...
0
votes
2
answers
143
views
Mysql 8 recursive query with two mandatory parents
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 ...
0
votes
1
answer
62
views
Query to calculate SUM of below top level Childs calculated amount
I have a Table TestPoolCalc, I need to show current node amount + sum of below top level Childs calculated amount. Please see the expected output
Table Script and Data
CREATE TABLE [dbo].[...
1
vote
0
answers
70
views
Display hierarchical relation on Excel or Power Bi
I'm trying to find a way to sort a hierarchy in Power Bi or Excel.
I would like to find a way to keep the (visual) structure in order. Keep the nesting between each parent and each child.
Here is the ...
0
votes
1
answer
83
views
Keeping a constant identifying value at the beginning of a recursively unioning cte
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 ...
1
vote
1
answer
101
views
Idiomatic approach to query hierarchical of heterogeneous data
Edit:
Maybe my problem is much more simple than I initially thought. My problem is in fact how to query complex objects (with nested objects) in relational databases. Maybe I just need to query each ...
0
votes
0
answers
130
views
Optimizing SQL Query Performance for Hierarchical Data Retrieval
I'm working on a project where I need to retrieve hierarchical data from a table stored in a SQL database. The table structure follows the adjacency list model, with each row containing a parent ID ...
2
votes
0
answers
122
views
AG Grid: In a treeList, can you hide (filter) all children yet still show the parent?
AG Grid: In a treeList, can you hide (filter) all children yet still show the parent?
Background: We have this problem:
We are using AG Grid's tree data model. As demonstratable on the documentation ...
1
vote
0
answers
100
views
Stored procedure logic fix needed for parent child relationships in data running on Synapse
I have a table which has hierarchical relationships.
Because I am using synapse, I can’t use recursion, so trying this below approach using a stored procedure.
My input data is :
----------------------...
2
votes
1
answer
63
views
Assistance to fix query to identify recursive relationships in data in SQL DW
I have a table which has hierarchical relationships.
My input data is
product_identifier parent_product_identifier Zone
------------------ ------------------------- ----
1 5 ...
1
vote
1
answer
58
views
Rebuild the hierarchy from a one column dataframe
I have the following dataframe:
Name Qty
0 Fruits
1 Apple 100
2 Mango 200
3 Vegetables
4 spinach 2
I want to rebuild the hierarchy of the dataset by using the ...
1
vote
1
answer
330
views
AG Grid: Can a hierarchical table with instantiated parents be flattened?
Use case
Illustrated below: A hierarchical table is two levels deep (“parents” and “children”). In some instances, our users need the hierarchy to flatten, so that the children are shown as equal to ...
0
votes
0
answers
40
views
MySQL Functional Index on a Varchar column with multi decimal sequence
So I have a table where we store a sequence value of what we call a "tree". Sort of looks like this
1
1.1
1.1.1
1.1.2
2
2.1
2.2
3
3.1
3.1.1
3.1.1.1
3.1.1.2
3.1.1.3
etc
etc
etc
Our ...
0
votes
1
answer
45
views
Create Leg Column in Hierarchical Data
I'm trying to add a column in my Select statement that can assign the leg number to the three legs I have. The leg number is always assigned at Level 1 in no particular order.
Note: my actual data is ...
0
votes
2
answers
174
views
Parent Child Path hierarchy in python using pandas
I'm trying to get child parent hierarchy in new pandas column. Currently my code looks like this, but it search for all parents, but it should search for the one in corresponding row.
Here is the ...
0
votes
1
answer
130
views
Need help flattening a multi-array item in Cosmos
I'm still somewhat inexperienced with Cosmos. I have a multi-array item that I need to flatten. What we have are multiple Project items with a variable number of Resources. Each Resource also has a ...
0
votes
0
answers
34
views
Solution for processing hierarchical structure with large number of leaf nodes in SQL
I'm working on a project which stores data of a tree-structured models like file systems and so on.
And in many cases the tree has large number of leaves in it and have unknown depth.
My project is ...