首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将子查询转换为连接

问将子查询转换为连接
EN

Stack Overflow用户
提问于 2021-07-05 19:11:43
回答 1查看 29关注 0票数 0

我正在努力提高我的查询性能,因为我正在处理大数据。(许多TB的数据)我正在研究Impala。

我使用的查询如下所示。这是子查询的形式。我不确定如何优化它。可能是JOINS。如果是,我不能将此子查询转换为连接。

请建议如何将此子查询转换为连接。我需要提高查询性能

代码语言:javascript
复制
select mytable.id,group_concat(mytable.acqid) as 'acqid',group_concat(mytable.address) as 'address'
from (select myinnertable.id, case when myinnertable.mykey = 'AcqId' then myinnertable.myvalue end as 'acqid',
             case when myinnertable.mykey = 'Address' then myinnertable.myvalue end as 'address'
      from (select id,mykey,myvalue
            from table1
            where table1.date_col BETWEEN '2021-05-02' and '2021-05-19' and mykey!='velList'
           ) myinnertable
     ) mytable
group by mytable.id;
EN

回答 1

Stack Overflow用户

发布于 2021-07-05 19:30:20

您正在做的事情可以在没有嵌套上下文的情况下得到简化。正如戈登所指出的,您只使用了一个表,但在结果中进行了3次遍历。我会确保它在(date_col, id, mykey)上有一个索引,以帮助优化拉取数据。

代码语言:javascript
复制
select 
        t1.id, 
        group_concat( case when t1.mykey = 'AcqId' 
                        then t1.myvalue end ) acqid,
        group_concat( case when t1.mykey = 'Address' 
                        then t1.myvalue end ) address
    from 
        table1 t1
    where 
            t1.date_col BETWEEN '2021-05-02' and '2021-05-19' 
        and t1.mykey != 'velList' 
    group by 
        t1.id;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68255145

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档