oracle with 子句从之前的查询表中赋值

问题描述 投票:0回答:1

我需要在第二个查询中使用先前查询结果中的值,同时使用

with clause

示例

with xtable as (
select t1.column1,
       t1.column2,
       t1.column3,
       t1.column4
from table1 t1
where t1.column1 in (1,2)
and t1.column4 = 'ut'
), ytable as 
(
select t2.column1,
       t2.column2,
       t2.column3,
       t2.column4
from table1 t2
where t2.column4 = xtable.column2 
)select * from xtable,ytable
oracle oracle11g
1个回答
0
投票

您可以在第二个查询中添加

xtable
为:

with xtable as (
select t1.column1,
       t1.column2,
       t1.column3,
       t1.column4
from table1 t1
where t1.column1 in (1,2)
and t1.column4 = 'ut'
), ytable as 
(
select t2.column1,
       t2.column2,
       t2.column3,
       t2.column4
from table1 t2,xtable x
where t2.column4 = x.column2 
)
© www.soinside.com 2019 - 2024. All rights reserved.