参考:https://www.cnblogs.com/tufujie/p/9413852.html https://www.cnblogs.com/bianxj/articles/12367919.html

    MySQL Explain 详解

    示例:

    1. EXPLAIN SELECT
    2. `aw`.`order_code` AS `order_code`,
    3. `aw`.`user_id` AS `user_id`,
    4. `aw`.`order_price` AS `total_amount`,
    5. `aw`.`order_price` AS `pay_amount`,
    6. 1 AS `order_status`,
    7. 1 AS `order_status`,
    8. `aw`.`create_time` AS `create_time`
    9. FROM
    10. `app_weigh_data` `aw`
    11. LEFT JOIN `app_order` `ao` ON concat(`aw`.`order_code`) = `ao`.`order_code`

    image.png
    两张表数据类型不一致 app_order表 order_code 是utf-8 ,但是 app_weigh_data 的 order_code 是 utf-8mb4
    image.png

    sql查询

    1. SELECT
    2. `app_order`.`order_code` AS `order_code`,
    3. `app_order`.`user_id` AS `user_id`,
    4. `app_order`.`total_amount` AS `total_amount`,
    5. `app_order`.`pay_amount` AS `pay_amount`,
    6. `app_order`.`pay_type` AS `pay_type`,
    7. `app_order`.`order_status` AS `order_status`,
    8. `app_order`.`create_time` AS `create_time`
    9. FROM
    10. `app_order` UNION
    11. SELECT
    12. `aw`.`order_code` AS `order_code`,
    13. `aw`.`user_id` AS `user_id`,
    14. `aw`.`order_price` AS `total_amount`,
    15. `aw`.`order_price` AS `pay_amount`,
    16. 1 AS `order_status`,
    17. 1 AS `order_status`,
    18. `aw`.`create_time` AS `create_time`
    19. FROM
    20. `app_weigh_data` `aw`
    21. LEFT JOIN `app_order` `ao` ON concat(`aw`.`order_code`) = `ao`.`order_code`

    如何处理?
    答: 把两张表的 order_code 数据类型改成一样的 ,utf-8

    app_order.sql
    app_weigh_data.sql