Oracle:一个查询的输出到另一个查询的输入
Oracle: Output of one query to input of another query
我需要加入两个查询,第一个查询的输出应该是 where 子句中第二个查询的输入,我该如何实现?
Select
Distinct
TRNSFR_SRC_ID,
DESCR_ORG,
SUBJECT,
CRSE_NBR,
DESCR1_FRMVW,
SUBJECT_TO,
CATALOG_NBR_TO,
FROM
TRNSFR_CRSE
WHERE
ORG_ID = ?
Select
Distinct
ATTR_VALUE
From TRNSFR_CRSE
Where
ORG_ID = ?
and SUBJECT = ?
and CRSE_NBR = ?
and SUBJECT_TO = ?
and CATALOG_NBR_TO = ?
and CRSE_ATTR = 'GHH'"
如果我假设第一个查询的输出是第二个查询的输入,那么使用下面的
Select
Distinct
ATTR_VALUE
From TRNSFR_CRSE
Where
(ORG_ID,SUBJECT,CRSE_NBR,SUBJECT_TO,,CATALOG_NBR_TO) in
(Select
DESCR_ORG,
SUBJECT,
CRSE_NBR,
SUBJECT_TO,
CATALOG_NBR_TO,
FROM
TRNSFR_CRSE
WHERE
ORG_ID = ?)
and CRSE_ATTR = 'GHH'"
Oracle 可以使这变得非常简单,但我不确定如何在这种情况下应用它。但是像这样:
select Distinct ATTR_VALUE
from TRNSFR_CRSE
where (ORG_ID, SUBJECT, CRSE_NBR, SUBJECT_TO, CATALOG_NBR_TO) IN
(Select TRNSFR_SRC_ID, SUBJECT, CRSE_NBR, SUBJECT_TO, CATALOG_NBR_TO
from TRNSFR_CRSE
where ORG_ID = ?
) and
CRSE_ATTR = 'GHH'
如果您知道子查询应该 return 不超过一行,则可以使用 =
而不是 in
。
我需要加入两个查询,第一个查询的输出应该是 where 子句中第二个查询的输入,我该如何实现?
Select
Distinct
TRNSFR_SRC_ID,
DESCR_ORG,
SUBJECT,
CRSE_NBR,
DESCR1_FRMVW,
SUBJECT_TO,
CATALOG_NBR_TO,
FROM
TRNSFR_CRSE
WHERE
ORG_ID = ?
Select
Distinct
ATTR_VALUE
From TRNSFR_CRSE
Where
ORG_ID = ?
and SUBJECT = ?
and CRSE_NBR = ?
and SUBJECT_TO = ?
and CATALOG_NBR_TO = ?
and CRSE_ATTR = 'GHH'"
如果我假设第一个查询的输出是第二个查询的输入,那么使用下面的
Select
Distinct
ATTR_VALUE
From TRNSFR_CRSE
Where
(ORG_ID,SUBJECT,CRSE_NBR,SUBJECT_TO,,CATALOG_NBR_TO) in
(Select
DESCR_ORG,
SUBJECT,
CRSE_NBR,
SUBJECT_TO,
CATALOG_NBR_TO,
FROM
TRNSFR_CRSE
WHERE
ORG_ID = ?)
and CRSE_ATTR = 'GHH'"
Oracle 可以使这变得非常简单,但我不确定如何在这种情况下应用它。但是像这样:
select Distinct ATTR_VALUE
from TRNSFR_CRSE
where (ORG_ID, SUBJECT, CRSE_NBR, SUBJECT_TO, CATALOG_NBR_TO) IN
(Select TRNSFR_SRC_ID, SUBJECT, CRSE_NBR, SUBJECT_TO, CATALOG_NBR_TO
from TRNSFR_CRSE
where ORG_ID = ?
) and
CRSE_ATTR = 'GHH'
如果您知道子查询应该 return 不超过一行,则可以使用 =
而不是 in
。