"제품"테이블에 모든 제품 세부 정보가 있습니다.
계층 구조로 표시하는 방법,
product_id product_type_id internal_name
1001 finishedgood nokia
1002 rawmaterial chip
1003 subassembly diaplay
1004 rawmaterial displaybase
그것은 노키아 휴대폰 (finishedgood)이 회사
칩 (rawmaterial), 디스플레이 (조립체)을 필요로하게하는 것을 의미한다. 다시
이제
"productassoc"테이블 세부
(rawmaterial)
displaybase 필요 디스플레이 (서브 어셈블리)를 만들기 위해
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
-----
.
의미, 내 쿼리
finishgood 수 있도록 필요한 모든 rawmaterials 및 하위 어셈블리를 반환해야합니다. 또한 서브 어셈블리에 필요한 원재료도 있습니다.
이것은 단지 샘플입니다. 나는 제품에 대해 약 100 가지 구성 요소를 가지고있었습니다.
희망이 도움이 될 수 있습니다 http://stackoverflow.com/questions/11064913/achieve-hierarchy-parent-child-relationship-in-an - 효과적이고 쉬운 방법 –