with recursive ps(product_code,description,parent_id) as (select product_code,description,parent_id from product_code where parent_id='cp' union all select b.product_code,b.description,b.parent_id from ps p join product_code b on p.product_code=b.parent_id ) Put @result1 the results into the following query out the quantities of each layer with recursive ps(product_code,description,parent_id) as (select product_code,description,parent_id from product_code where parent_id=@result1 union all select b.product_code,b.description,b.parent_id from ps p join product_code b on p.product_code=b.parent_id ) select shipper.customer_id,sum(sh.quantity),description=@result1 from (((select * from ps union all select product_code,description,parent_id from product_code where product_code=@result1 ) a join part on a.product_code=part.product_code) join shipper_line sh on part.part_id=sh.part_id) join shipper on sh.trans_no=shipper.trans_no group by shipper.customer_id,description |
This forum is for answering questions about SQL Anywhere, not doing your homework.