Tagged Questions
2
votes
1answer
112 views
Recursive SQL with more tables
I've a question about the use of recursive SQL in very particular situation which I describe below.
I have a table A with a (ID, value) schema and these sample rows:
(1,1000)
(2,800)
(3,300)
...
1
vote
1answer
93 views
SQL Hierarchy and Joined Table Counts
I have a Employee Table and a Projects table. An employee can only be in 1 proj and have the employee table as a hierarchy with ID and ReportsTO ID . I need to get the counts of the projects where ...
1
vote
1answer
41 views
How do I structure a bunch of items that chain together in a MySQL database?
I apologize for the vagueness of my question title, but I don't even know what to call what I'm trying to accomplish.
The best way to describe what I want is that I want to be able to chain a bunch ...
1
vote
1answer
132 views
Recursive query to get all descendants of row
I have a Menu system where each item can have a parent. So the structure is something like this
What I want to do is display a 'bread crumb' style list of links for the current page. So if the user ...
1
vote
1answer
178 views
Bill of Materials Query
I currently have 2 tables as follows within my database:
Table: SampleProducts
SampleProductsId (PK) Name
1 A
2 B
3 ...
2
votes
0answers
690 views
Recursive CTE in MySql for tree structure (adjacency list)
I'm just starting out with MySQL (I come from using SQL Server previously). I haven't yet started implementing anything in MySQL, just researching how to do things and what problems I might ...
1
vote
0answers
79 views
How to speed up a recursive CTE
Given the following recursive CTE (simplified a bit for my example):
WITH myCTE (sort, parentid, myid, level, somedata)
AS
(
-- Anchor member definition
SELECT
CAST(ROW_NUMBER() ...
1
vote
0answers
142 views
Using the most efficient aggregation method in SQL Server 2008 R2 to sum up child rows in same table
I need to find a way to do an INSERT into the same table (named ResultsHistory) by summing up the child row totals without using a CURSOR in MSSQL. We currently use a CURSOR in a stored procedure to ...
1
vote
0answers
71 views
sql categorypath of parent categories in join
i have tried and searched a while, and i dont think there is much missing, but i need help:
I can only modify the query by adding a (left) join becouse its an automatic created query
So its beginning ...
1
vote
0answers
466 views
Google Interview Question: Recursive Query or Common Table Expression for the following scenario
I have two tables TableA and TableB in the following fashion:
Table A(ID, PairId)
--Here the Pair represented by PairId will always have 2 elements in it.
Data:
100,1
101,1
-----
104,2
109,2
...
0
votes
0answers
47 views
Splitting/Dividing rows SQL
I have a table of following columns Item(item_id, parent_item_id, item_type, quantity), and I would like to be able to split a row of n rocks into multiple rows, whose sum of quantity equals the sum ...
0
votes
0answers
67 views
SQL Design and Normalization Help Please
I'm tasked with creating a cross-walk for information between a variety of vendor drug-information databases. Some of them are well structured, and it is obvious that the vendor understands the ...
0
votes
0answers
177 views
T-SQL Finding Where Used Item
We have a Parts BOM table with a parent/child hierarchy (7 levels deep). I'm trying to write a report for 'Where a part is used' and the problem is that the query is too slow. This table contains ...
0
votes
0answers
101 views
Populate Random records with apriory known distribution in DB2 / SQL
To make it simple, here is the story: I have to create test data of, say, country names.
I have a simple table like this one:
create table countries(name varchar(16), percentage float);
populating ...
0
votes
0answers
102 views
CTE, recursive search in 2 diferent tables
i have 2 queries go gather data from different tables, both recursive, but closelly related.
Both work well:
First pulls subsidiaries :
with
relations as
(
select orgid as ...