首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >优化sql脚本

优化sql脚本
EN

Stack Overflow用户
提问于 2018-03-23 12:59:50
回答 1查看 55关注 0票数 0

大家好,我正在寻找优化这个SQL脚本的方法,以获得更好的性能,有谁可以帮助我吗

代码语言:javascript
复制
With accounts As 
(
    select account_id, creation_date 
    from account 
    where program_distributor = 'brinks'
    and channel = 'online'
    and creation_year = 2017
),
Form_opens as 
(
    select session_id, log_time 
    from web_action_log 
    where web_action = 'open_dd_form'
),
Mapping as 
(
    select session_id, account_id 
    from web_link
)
Select
    trunc (acc.creation_date), 
    count(distinct acc.account_id), 
    count (distinct fo.account_id) 
from accounts acc 
left outer join mapping mp
    on acc.account_id = mp.account_id
Left outer join form_opens fo
    on mo.session_id = fo.session_id and 
    acc.creation_date > do.log_time
Group by trunc(acc.creation_date)
Order by 1;
EN

回答 1

Stack Overflow用户

发布于 2018-03-23 15:28:12

在下面尝试,query.You可以跳过with子句的编写,因为您没有多次查询with子句输出表。在联接过程中添加筛选条件也可以提高性能。

代码语言:javascript
复制
select
    trunc (acc.creation_date), 
    count(distinct acc.account_id), 
    count (distinct fo.account_id) 
from account acc 
left outer join web_link mp
    on acc.account_id = mp.account_id
left outer join web_action_log fo
    on mo.session_id = fo.session_id 
    and acc.creation_date > fo.log_time 
    and fo.web_action = 'open_dd_form'
where   acc.program_distributor = 'brinks'
    and acc.channel = 'online'
    and acc.creation_year = 2017
group by trunc(acc.creation_date)
order by 1;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49442643

复制
相关文章

相似问题

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