Commit 488f99b512390f497556f31a7909cb5804c1343c
1 parent
ed5f3a6b
fix: selectCustomerDealCycleGroupByProductId使用LEFT JOIN替换子查询
Showing
1 changed file
with
5 additions
and
2 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/statistics/CrmStatisticsCustomerMapper.xml
| ... | ... | @@ -243,14 +243,17 @@ |
| 243 | 243 | |
| 244 | 244 | <select id="selectCustomerDealCycleGroupByProductId" |
| 245 | 245 | resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.customer.CrmStatisticsCustomerDealCycleByProductRespVO"> |
| 246 | - SELECT (SELECT name FROM crm_product WHERE id = product.id) AS product_name, | |
| 246 | + SELECT product.name AS product_name, | |
| 247 | 247 | IFNULL(TRUNCATE(AVG(TIMESTAMPDIFF(DAY, customer.create_time, contract.order_date)), 1), 0) AS customer_deal_cycle, |
| 248 | 248 | COUNT(DISTINCT customer.id) AS customer_deal_count |
| 249 | 249 | FROM crm_customer AS customer |
| 250 | 250 | LEFT JOIN crm_contract AS contract ON customer.id = contract.customer_id |
| 251 | - LEFT JOIN crm_contract_product AS product ON product.contract_id = contract.id | |
| 251 | + LEFT JOIN crm_contract_product AS contract_product ON contract_product.contract_id = contract.id | |
| 252 | + LEFT JOIN crm_product AS product ON contract_product.product_id = product.id | |
| 252 | 253 | WHERE customer.deleted = 0 |
| 253 | 254 | AND contract.deleted = 0 |
| 255 | + AND contract_product.deleted = 0 | |
| 256 | + AND product.deleted = 0 | |
| 254 | 257 | AND contract.audit_status = ${@cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum@APPROVE.status} |
| 255 | 258 | AND customer.owner_user_id IN |
| 256 | 259 | <foreach collection="userIds" item="userId" open="(" close=")" separator=","> | ... | ... |