0

我有查询,我在下表之间有以下关系

select * from PRODGP_STRUCTURE
select * from PRODGP_STR_LINK
select * from PRODUCT_GROUP
select * from PROD_PGRP_LINK
select * from PRODUCT

关系是……

select pstr.PSTR_NAME, PG.PRGP_NAME, PRD.PROD_NAME
from prodgp_structure pstr
JOIN PRODGP_STR_LINK pgstrlnk
  ON pgstrlnk.PSTR_ID = pstr.PSTR_ID  
JOIN PRODUCT_GROUP pg 
  ON pgstrlnk.PRGP_CHILD_ID = PG.PRGP_ID
JOIN PROD_PGRP_LINK prdprdgp
  ON prdprdgp.PRGP_ID = pg.PRGP_ID
JOIN product prd
  ON prdprdgp.PROD_ID = prd.PROD_ID;

我提出了以下查询,

select * from PRODGP_STRUCTURE where pstr_id in 
(select pstr_id from PRODGP_STR_LINK where PRGP_CHILD_ID  in
(select  prgp_id from PRODUCT_GROUP where PRGP_ID in ( select  PRGP_ID from PROD_PGRP_LINK where PROD_ID in ( select PROD_ID from product where PROD_ID=2))))

请让 e 知道是否有任何其他方式来编写此查询..!!

4

1 回答 1

0

将您的表内部连接在一起,然后您只需要按 PROD_ID 过滤

SELECT pstr.PSTR_NAME, PG.PRGP_NAME, PRD.PROD_NAME
FROM prodgp_structure pstr
INNER JOIN PRODGP_STR_LINK pgstrlnk
  ON pgstrlnk.PSTR_ID = pstr.PSTR_ID  
INNER JOIN PRODUCT_GROUP pg 
  ON pgstrlnk.PRGP_CHILD_ID = PG.PRGP_ID
INNER JOIN PROD_PGRP_LINK prdprdgp
  ON prdprdgp.PRGP_ID = pg.PRGP_ID
INNER JOIN product prd
  ON prdprdgp.PROD_ID = prd.PROD_ID
WHERE prd.PROD_ID = 2;
于 2012-11-09T10:26:11.290 回答