加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

有没有办法在Oracle 11g SQL中给子查询别名?

发布时间:2020-12-12 13:48:20 所属栏目:百科 来源:网络整理
导读:有没有办法在Oracle 11g中给出一个别名的子查询: select * from (select client_ref_id,request from some_table where message_type = 1) abc,(select client_ref_id,response from some_table where message_type = 2) defgwhere abc.client_ref_id = def
有没有办法在Oracle 11g中给出一个别名的子查询:
select * 
from
    (select client_ref_id,request from some_table where message_type = 1) abc,(select client_ref_id,response  from some_table where message_type = 2) defg
where
    abc.client_ref_id = def.client_ref_id;

否则有一种方法可以基于client_ref_id来加入两个子查询.我意识到有一个自我加入,但在数据库上,我运行在一个自联接可能需要5分钟才能完成(在实际的查询中有一些额外的逻辑,我正在运行,但我已经确定自我加入是什么导致问题).个别子查询只需要几秒钟就可以完成.自我连接查询看起来像:

select st.request,st1.request
from
    some_table st,some_table st1
where 
    st.client_ref_id = st1.client_ref_id;
WITH abc as (select client_ref_id,request from some_table where message_type = 1)
select * 
from abc
    inner join 
    (select client_ref_id,response  from some_table where message_type = 2) defg
on   abc.client_ref_id = def.client_ref_id;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读