频道栏目
首页 > 数据库 > SQL Server > 正文
sql语句查询时间的方式比较(代码实例)
2018-07-19 14:45:09         来源:gaoweipeng238的博客  
收藏   我要投稿

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倍,了解下原因

点击复制链接 与好友分享!回本站首页
上一篇:WPF操作SQL SERVER 数据库实例讲解
下一篇:SQLServer的基本SQL实例解析
相关文章
图文推荐
点击排行

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站