INSERT IGNORE INTO tb_pluss_merchant_order_statistics(`merchantCode`, `count`, `totalFee`, `retCount`, `retFee`, `startDate`, `endDate`)
SELECT
mbi.merchantCode,
COUNT(IF(mo.`status` = 1, 1, NULL)) count,
SUM(IF(mo.`status` = 1, consumeFee, 0.00) ) totalFee,
COUNT(IF(mo.`status` = 2, 1, NULL)) retCount,
SUM(IF(mo.`status` = 2, consumeFee, 0.00) ) retFee,
#{startDate},
#{endDate}
FROM
tb_pluss_merchant_base_info mbi
LEFT JOIN tb_pluss_merchant_order mo ON mbi.merchantCode = mo.merchantCode
WHERE
createDate BETWEEN #{startDate}
AND #{endDate}
GROUP BY
merchantCode;
INSERT IGNORE INTO tb_pluss_merchant_order_statistics(`merchantCode`, `totalFee`, `count`, `retFee`, `retCount`, `startDate`, `endDate`)
SELECT merchantCode, SUM(totalFee) totalFee, SUM(count) count, SUM(retFee) retFee, SUM(retCount) retCount, '1970-01-01', '2099-12-31'
FROM tb_pluss_merchant_order_statistics mos GROUP BY merchantCode;