Commit 222c9b86 by 春觉晓

修改门店存量分析接口,优化流失门店sql

1 parent 5fa6033d
......@@ -642,53 +642,47 @@
</select>
<select id="countLostMerchantByBizType" resultType="java.lang.Integer">
SELECT
count(distinct merchant_id) AS lost_merchant_count
FROM dj_smartcarlife.dj_car_life_service_merchant_bi t1
WHERE
t1.deleted_flag = 'N'
SELECT COUNT(1) AS lost_merchant_count
FROM
(SELECT merchant_id
FROM dj_smartcarlife.dj_car_life_service_merchant_bi
WHERE deleted_flag = 'N'
<choose>
<when test="bizType == 2">
and has_ext_warranty = 1
</when>
<when test="bizType == 3">
and has_benefits = 1
</when>
<when test="bizType == 4">
and has_light_mod = 1
</when>
</choose>
<![CDATA[
AND stat_date >= #{statDate} - INTERVAL 59 DAY
AND stat_date <= #{statDate}
]]>
<if test="merchantIds != null and merchantIds.size > 0">
and t1.merchant_id in
AND merchant_id IN
<foreach item="item" index="index" collection="merchantIds" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="excludeIds != null and excludeIds.size > 0">
and t1.merchant_id not in
and merchant_id not in
<foreach item="item" index="index" collection="excludeIds" separator="," open="(" close=")">
#{item}
</foreach>
</if>
AND EXISTS (
SELECT 1
FROM dj_smartcarlife.dj_car_life_service_merchant_bi t2
WHERE
t2.merchant_id = t1.merchant_id
<![CDATA[
AND t2.stat_date >= #{statDate} - INTERVAL 59 DAY -- 传入的统计日期
AND t2.stat_date <= #{statDate}
]]>
<choose>
<when test="bizType == 2">
and t2.has_ext_warranty = 1
</when>
<when test="bizType == 3">
and t2.has_benefits = 1
</when>
<when test="bizType == 4">
and t2.has_light_mod = 1
</when>
</choose>
AND t2.deleted_flag = 'N'
)
AND NOT EXISTS (
GROUP BY merchant_id) a
WHERE NOT EXISTS (
SELECT 1
FROM dj_smartcarlife.dj_car_life_service_merchant_bi t3
WHERE
t3.merchant_id = t1.merchant_id
WHERE t3.merchant_id = a.merchant_id
AND t3.deleted_flag = 'N'
<![CDATA[
AND t3.stat_date >= #{statDate} - INTERVAL 29 DAY
AND t3.stat_date <= #{statDate}
AND t3.stat_date >= #{statDate} - INTERVAL 29 DAY
AND t3.stat_date <= #{statDate}
]]>
<choose>
<when test="bizType == 2">
......@@ -701,8 +695,7 @@
and t3.has_light_mod = 1
</when>
</choose>
AND t3.deleted_flag = 'N'
);
)
</select>
<select id="countHistoryMerchant" resultType="java.lang.Integer">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!