oracle oracle查询中的WITH AS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15063739/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WITH AS in oracle query
提问by Rogbi
What if I have different tables on my oracle query, how can I group them in one WITH AS
query:
如果我的 oracle 查询中有不同的表怎么办,我如何将它们分组为一个WITH AS
查询:
WITH A AS (
SELECT A,B FROM TABLE1,
SELECT C FROM TABLE2 ---> ??
)
I want to translate my query with "with as" function including different tables. but it seems selecting another column form other table is not working.
我想用“with as”函数翻译我的查询,包括不同的表。但似乎从其他表中选择另一列不起作用。
Table1
A B
data1 data1
Table2
C
Data1
i just want to query them into one "With AS" statement. :)
我只想将它们查询为一个“With AS”语句。:)
output should be
输出应该是
A B C
data1 data1 data1
回答by APC
There is no obvious reason why you need to use sub-query factoring but here is how to do it:
没有明显的原因需要使用子查询分解,但这里是如何做到的:
with data as ( select table1.A, table1.B, table2.C
from table1 cross join table2 )
select * from data;
Obviously as your question doesn't provide any join criteria a cartesian product is the result you can have. I suspect that isn't what you want but unless you most sufficient details who can tell?
显然,由于您的问题没有提供任何连接标准,因此您可以获得笛卡尔积。我怀疑这不是你想要的,但除非你最充分的细节谁能告诉?
回答by spin_eight
WITH A AS (
SELECT A, B FROM TABLE1
UNION/UNION ALL
SELECT '','',C FROM TABLE2
)