我有「產品」表,它包含所有產品的詳細信息。
如何在層次結構中顯示,,
product_id product_type_id internal_name
1001 finishedgood nokia
1002 rawmaterial chip
1003 subassembly diaplay
1004 rawmaterial displaybase
;那意味着把諾基亞手機(finishedgood)公司需要
芯片(原材料),顯示器(組件)。使顯示器(組件),它需要再次
displaybase(原材料)
現在 「productassoc」 表的詳細信息
product_id product_id_to
1001 1002
1001 1003
1003 1004
我的問題:我想以檢索所需的諾基亞製造
此查詢返回需要的1級商品(我也想顯示
子組件所需的原料)
查詢:
select pa.product_id,pa.product_id_to,p.product_type_id,p.internal_name
from product p,
product_assoc pa
where p.product_id=pa.product_id_to and pa.product_id=1001
O/P
product_id product_id_to product_type_id internal_name
1001 1002 rawmaterial chip
1001 1003 subassembly display
-----
我想顯示所需的子組件還rawmaterials。
意思是說,我的查詢應該返回完成所需的所有原材料和子組件。以及部件所需的原材料。
這只是一個示例。我有一個產品約100個組件。
希望這可能是有用的:http://stackoverflow.com/questions/11064913/achieve-hierarchy-parent-child-relationship-in-an - 有效和寬鬆路 – 2013-07-01 08:17:18