1. 程式人生 > >sql語句查詢時間比較

sql語句查詢時間比較

SELECT
    e.id AS "id",
    e.enterprise_name AS "enterpriseName",
    y.industry_name AS "industryName",
    d.district_name AS "districtName",
    v.level_value AS "levelValue",
    v.sumScore as "sumScore"
FROM
    
        (
            (
                enterprise e
                LEFT JOIN industry y ON e.industry_id = y.id
            )
            LEFT JOIN district d ON e.district_id = d.id
        )


        LEFT JOIN 

                (
                        SELECT i.enterprise_id,SUM(i.index_score) sumScore,l.level_value  from index_enterprise_year i LEFT JOIN level_enterprise_year l ON i.enterprise_id = l.enterprise_id
                        AND l. YEAR = i.year where  i.year=2017 GROUP BY i.enterprise_id 
                )  v 

        ON  e.id=v.enterprise_id
where 
    e.enterprise_status = 10
ORDER BY sumScore DESC
LIMIT 10

SELECT
    e.id AS "id",
    e.enterprise_name AS "enterpriseName",
    e.business_registration_no AS "businessRegistrationNo",
    e.organization_code AS "organizationCode",
    e.unified_credit_code AS "unifiedCreditCode",
    e.legal_person_name AS "legalPersonName",
    e.enterprise_telephone AS "enterpriseTelephone",
    e.registered_address AS "registeredAddress",
    e.longitude AS "longitude",
    e.dimension AS "dimension",
    e.industry_id AS "industryId",
    y.industry_name AS "industryName",
    e.district_id AS "districtId",
    d.district_name AS "districtName",
    e.formula_id AS "formulaId",
    e.enterprise_status AS "enterpriseStatus",
    SUM(i.index_score) sumScore,
    l.level_value
FROM
    (
        (
            (
                enterprise e
                LEFT JOIN industry y ON e.industry_id = y.id
            )
            LEFT JOIN district d ON e.district_id = d.id
        )
        LEFT JOIN level_enterprise_year l ON e.id = l.enterprise_id
        AND l. YEAR = 2017
    )
LEFT JOIN index_enterprise_year i ON e.id = i.enterprise_id
AND i. YEAR = 2017
GROUP BY
    e.id
HAVING
    e.enterprise_status = 10
ORDER BY
    sumScore DESC
LIMIT 10

兩條語句時間相差75倍,瞭解下原因