提高mysql的查询效率(时间转换为时间戳比对)

 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
                = #{today_timestamp}
                ]]>
                AND sbo.pay_status = '1'
        GROUP BY
            om.mer_id
        ORDER BY
            totalAmount DESC

重点在于

= #{today_timestamp}
                ]]>

原先都是这种形式,这种形式查询速度较慢

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

这个只对当天的信息有用,其他的可以综合考虑,因为数据量过大,所以中间还加了索引

你可能感兴趣的:(提高mysql的查询效率(时间转换为时间戳比对))