oracle 连接两个选择语句的结果
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13968075/
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
Concatenate result of two select statements
提问by Mayur Sharma
My query is something like:
我的查询是这样的:
concatenate(
(select col1 from table1) , ( select col1.substr(1,<tillENd>) )
)
This works fine if both sub-selects return one row and one column. In my case, both will give multiple rows but one column.
如果两个子选择都返回一行和一列,则这可以正常工作。在我的情况下,两者都会给出多行但一列。
I want to concatenate them row-wise. How can I do this?
我想按行连接它们。我怎样才能做到这一点?
Update: complete queries are something like the following.
更新:完整的查询类似于以下内容。
Query 1:
查询 1:
select col3
from tabl2
where col2 in (select substr(A,1,instr(A,'_',-1)-1)
from ( select substr(col1,1,instr(col1,'/')-1) as A
from ( select col1 from tabl1 )
)
)
seond select query:
第二个选择查询:
select substr(col1,instr(col1,'/')) as A1
from ( select col1
from tabl1 )
回答by David Aldridge
select ...
from ...
union all
select ...
from ...
Or if you use UNION instead of UNION ALL the complete result set is subject to a DISTINCT operation.
或者,如果您使用 UNION 而不是 UNION ALL,则完整的结果集受 DISTINCT 操作的约束。
回答by APC
Now that you have provided some sample queries it is easier for us to offer a solution.
现在您已经提供了一些示例查询,我们可以更轻松地提供解决方案。
Regarding your additional requirement, I assume you don't want to match the void strings, so the easiest thing is to filter them out in the sub-query.
关于您的额外要求,我假设您不想匹配空字符串,因此最简单的方法是在子查询中将它们过滤掉。
with data as ( select substr(col1,1,instr(col1,'/')-1) as A
, substr(col1,instr(col1,'/')) as A1
from tabl1
where instr(col1,'/') > 0 )
select tabl2.col3
, data.A1
from data
join tabl2
on tabl2.col2 = substr(data.A,1,instr(data.A,'_',-1)-1);