Mysql query to improve the efficiency (ratio of time to a timestamp)

 SELECT
            om.mer_name AS merName,
            IFNULL( SUM( sbo.total_amount ), 0 ) AS totalAmount,
            sum( CASE WHEN sbo.total_amount > 0 THEN 1 ELSE 0 END ) AS orderTotal,
            om.mer_addr AS merAdress,
            om.contact_person AS contactPerson,
            om.contact_mobile AS contractMobile,
            om.mer_id AS merId
        FROM
            o2o_merchant AS om
                LEFT JOIN sdb_b2c_orders AS sbo ON sbo.merchant_bn = om.mer_id
                <![CDATA[
                  AND sbo.createtime >= #{today_timestamp}
                ]]>
                AND sbo.pay_status = '1'
        GROUP BY
            om.mer_id
        ORDER BY
            totalAmount DESC

Focuses on

<![CDATA[
                  AND sbo.createtime >= #{today_timestamp}
                ]]>

This is the original form, this form of query slow

FROM_UNIXTIME( sbo.createtime, '%Y-%m-%d' )

This information is useful only for the day, the other can be considered, because the data is too large, so the middle also added index

Guess you like

Origin blog.csdn.net/LuckFairyLuckBaby/article/details/90405426