473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

recursive query

1
Hello

I have more than one tables joined in one query
One of those tables has child and parent fields

for example

X Y
1 0
2 0
3 1
4 1
5 3
6 3
7 4
8 2


where X is child and Y is parent so as the table is represented with tree.

Now when making join each X got a Quantity Sold from another table


X Y Quantity sold
1 0 20
2 0 12
3 1 16
4 1 5
5 3 30
6 3 18
7 4 7
8 2 5

what I want to do is summing all quantities of all children under each value plus its value .and if it has no children select its value.

so as



X Y Quantity sold Quantity sum
1 0 20 96
2 0 12 17
3 1 16 64
4 1 5 12
5 3 30 30
6 3 18 18
7 4 7 7
8 2 5 5

Now I can get correct values in first level.so any ideas ?

Thanks in advance
Jun 18 '10 #1
1 2135
amitpatel66
2,367 Expert 2GB
Can you post what you have tried so far?
Jul 12 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Perttu Pulkkinen | last post by:
I need to find toplevel image categories and a) number of images directly in them and b) number of subcategories directly in those topcategories. In toplevel image categories "icat_parent_id IS...
6
by: Tim Pascoe | last post by:
I have a database which stores information about organisms collected during sediment toxicology research. For each sample, organisms in sediment are collected and identified taxonomically (Order,...
14
by: Bob | last post by:
Hi there, Need a little help with a certain query that's causing a lot of acid in my stomach... Have a table that stores sales measures for a given client. The sales measures are stored per...
4
by: JayCallas | last post by:
Went looking for an answer but not really sure what phrases to look for. Just decided to post my question. I have a collection of groups which contain items. I also have a collection of users...
2
by: CSN | last post by:
I have a table with these columns: id, node, parent_node_id The top-most nodes would have a parent_node_id of NULL. Is it possible to get a node, and all its parent nodes, in a single query?...
1
by: ozcanseker | last post by:
I am trying to write a product-row material cost program. Every product consists of row materials. When I sum up cost of row materials of each product I can find cost of products. But when the row...
3
by: NatRoger | last post by:
Hi, We are using DB2 V7 (MVS) in our shop, which dont have the luxury of the 'WITH clause' - CTE support to accomplish recursive queries. Here is my problem - Table1 From-ID To-ID A1 ...
1
by: =?iso-8859-15?Q?Paul_Gr=F8stad?= | last post by:
Hi. I'm very new to Oracle (and databases in general), and I have a problem that most of you people probably will find very easy, but I just can't figure it out... I'm trying to create a...
2
by: Jim Devenish | last post by:
I have a table named StockItems with field: StockItemID QuantityInStock I am creating assemblies of stock items and have another table named StockItemAssemblies with fields:...
0
by: Pivot_Tables | last post by:
Please follow the below link as this post is continuation from the below post. http://groups.google.com/group/comp.databases.ibm-db2/browse_thread/thread/1589589ccf38eb0a Hi Guys, I got...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.