0

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

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

分类 产品表 分类 产品表

order_details 表 order_details 表

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

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

           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;
4

1 回答 1

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
  )
于 2017-03-19T16:26:47.843 回答