从两个表重建oracle层次结构查询

时间:2017-03-17 16:40:43

标签: oracle oracle12c hierarchical-query

我正在为下表进行oracle层次查询 Classification_ProductOrder_details

分类产品的Classification_id将根据用户选择存储在Order_details

分类产品表 Classification Product table

Order_details表 Order_details table

我想从Order_details表中选择所有具有父LED Screen的产品,无论孩子是32英寸还是50英寸或索尼,都会返回所有父母LED Screen的产品三星等等

我尝试使用下面的查询,但是它的重放行很多

           SELECT B.CLASSIFICATION_ID, LEVEL AS VLEVEL, A.CATEGORY_ID, A.CATEGORY_DESC, CONNECT_BY_ISLEAF AS leaf
             FROM PRODUCT_CLASSIFICATION A, ORDER_DETAILS B
            WHERE A.STATUS = 1 and b.created_on like sysdate--AND leaf =1 
       START WITH A.CATEGORY_ID IS NULL
       CONNECT BY A.CATEGORY_ID = PRIOR A.CLASSIFICATION_ID
ORDER SIBLINGS BY A.CLASSIFICATION_ID;

1 个答案:

答案 0 :(得分:0)

select od.*
from order_details od
where
  od.classification_id in (
    select p.classification_id
    from product p
    start with p.category_desc = 'LED Screen'
    connect by prior p.classification_id = p.category_id
  )