【问题标题】:Take customer count of all customers specific to region and对特定于区域的所有客户进行客户计数,并
【发布时间】:2016-10-05 05:00:07
【问题描述】:
select 
                "pct_customers_count"=isnull((select  count(customer_code)  from CRM..pct_customers where status <> "R" and add_branch=t3.c_branchcode),0) 
                ,"pct_arch_customers_count"=isnull((select  count(customer_code)  from CRM..pct_customers_arch where status <> "R" and add_branch=t3.c_branchcode) ,0)
                ,"crms_customers_count"= isnull((select  count(customer_code)  from CRMS..crms_customer_master where status <> "R" and add_branch=t3.c_branchcode) ,0)
                ,"crms_customers_daily_count"=isnull((select  count(customer_code)  from CRMS..crms_custdaily_master where status <> "R" and add_branch=t3.c_branchcode),0)
            from 
                ums..admin_regions t1 
                ,ums..admin_branches t2
                ,ums..branch_master t3
            where 
                t1.reg_code ='ZZZZ'
                and t2.reg_grandpa = t1.reg_code
                and t3.c_branchcode = t2.branch_code

下面我给出了我使用的表的总行大小

  • pct_customers:720227
  • pct_customers_arch: 341500
  • crms_customer_master:999005
  • crms_custdaily_master:929022

最后三个表获取分支代码,并将其提供给 pct_customers_table、pct_customers_arch、crms_customer_master 和 crms_custdaily_master 用于统计客户数量。

问题

这个查询对我们的数据库服务器造成了很大的负担。如何优化这个查询,以便在不到一分钟的时间内搜索数据库。我试图通过连接来简化查询,但没有成功。

我找到的解决方案

将计数写入表格并使用新表格将其显示到新页面。我知道这是一个很好的解决方案,但感觉它不是直接的解决方案。所以如果你们知道我的问题的任何其他解决方案,请分享。

【问题讨论】:

  • 欢迎来到 Stack Overflow!这个问题是题外话,因为它不是关于编程问题。你应该考虑在Code Review发帖。

标签: java mysql sql-server sybase


【解决方案1】:

您需要为每个表创建一个索引;要索引的列是 status 和 add_branch。

【讨论】:

    猜你喜欢
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    • 2013-10-31
    • 2016-05-27
    • 2018-12-17
    • 1970-01-01
    • 2021-01-28
    • 2018-02-03
    相关资源
    最近更新 更多