我正在为下表进行oracle层次查询
Classification_Product
和Order_details
表
分类产品的Classification_id
将根据用户选择存储在Order_details
我想从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;
答案 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
)