获取特定于区域的所有客户的客户数量,以及
Take customer count of all customers specific to region and
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
下面我给出了我使用的 tables 的总行大小
- pct_customers:720227
- pct_customers_arch: 341500
- crms_customer_master:999005
- crms_custdaily_master:929022
后三个table得到分支代码,交给pct_customers_table,pct_customers_arch,crms_customer_master和crms_custdaily_master 统计客户数量。
问题
这个查询给我们的数据库带来了很大的负担 server.How 我可以优化这个查询以便搜索不到一分钟吗 database.I 试图通过连接来简化查询但是没有成功.
我找到的解决方案
CRONing 计数到 table 并使用新的 table 我将它显示到新的 page.I 知道这是一个很好的解决方案,但感觉它不是直的 solution.So 如果你们知道我的问题的任何其他解决方案,请分享。
您需要为每个 table 创建一个索引;要索引的列是状态和 add_branch.
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
下面我给出了我使用的 tables 的总行大小
- pct_customers:720227
- pct_customers_arch: 341500
- crms_customer_master:999005
- crms_custdaily_master:929022
后三个table得到分支代码,交给pct_customers_table,pct_customers_arch,crms_customer_master和crms_custdaily_master 统计客户数量。
问题
这个查询给我们的数据库带来了很大的负担 server.How 我可以优化这个查询以便搜索不到一分钟吗 database.I 试图通过连接来简化查询但是没有成功.
我找到的解决方案
CRONing 计数到 table 并使用新的 table 我将它显示到新的 page.I 知道这是一个很好的解决方案,但感觉它不是直的 solution.So 如果你们知道我的问题的任何其他解决方案,请分享。
您需要为每个 table 创建一个索引;要索引的列是状态和 add_branch.