请参阅别名为FROM子句中的表的其他SQL SELECT语句

时间:2021-08-01 13:16:50

I have a very large query that follows the format below:

我有一个非常大的查询,遵循以下格式:

select ...
  from ( select field1,
                field2
           from some_table ) table1,
       ( select field1,
                field3
           from other_table ) table2

 where .....

Is is possible for me to refer to one of the tables "defined" in the from clause, lets say table1, in one of the other table definitions in the from clause?

我是否可以在from子句中引用其中一个“定义”的表,比如table1,在from子句中的其他一个表定义中?

For example:

select ....
  from ( select field1,
                field2
           from some_table ) table1,
       ( select table1.field1,
                field3
           from other_table,
                table1 ) table2

 where .....

Disclaimer: What I am trying to do is not as simple as the example above. The example is simply to illustrate the idea.

免责声明:我想做的并不像上面的例子那么简单。这个例子只是为了说明这个想法。

2 个解决方案

#1


WITH
table1 AS
        (
        SELECT  field1, field2
        FROM    some_table
        ),
table2 AS
        (
        SELECT  field1, field2
        FROM    other_table, table1
        )
SELECT  *
FROM    table2

#2


If you are using SQL 2005, you can use Common Table Expressions for doing what you are trying; Quassnoi gives us an example, in Oracle I don't know how to achieve it though

如果您使用的是SQL 2005,则可以使用Common Table Expressions来执行您正在尝试的操作; Quassnoi给了我们一个例子,在Oracle中我不知道如何实现它

#1


WITH
table1 AS
        (
        SELECT  field1, field2
        FROM    some_table
        ),
table2 AS
        (
        SELECT  field1, field2
        FROM    other_table, table1
        )
SELECT  *
FROM    table2

#2


If you are using SQL 2005, you can use Common Table Expressions for doing what you are trying; Quassnoi gives us an example, in Oracle I don't know how to achieve it though

如果您使用的是SQL 2005,则可以使用Common Table Expressions来执行您正在尝试的操作; Quassnoi给了我们一个例子,在Oracle中我不知道如何实现它