• sql 联合查询速度慢,需要对其进行分组


    分组:
    SELECT   * FROM(
    SELECT ROW_NUMBER() OVER(ORDER BY  ProjID) as row_number,* FROM (

    select ProjApplyDate,projProperty,ProjID,ProjStatusCurrent,ProjGuId,ProjEtpId,ProjRegionId,ProjName,ProjAddress,ProjAreaSize,ProjCost,ProjCreateTime,ProjChargePerson,ProjChargePersonPhone,ProjApplyEtp,ProjApplyPerson,ProjApplyPersonPhone,ProjConstructEtp,ProjConstructPM,ProjConstructPMPhone,ProjDirector,ProjDirectorPhone,ProjSafeOrgz,ProjCode,ProjIsEnable
    ,min(ConSignDate) as ConSignDate,max(ConBalanceDate) as ConBalanceDate  
    from  dbo.fn_GetProjectsByUserId(100093) as p INNER join (select cog.ConProjId,cog.ConSignDate,cog.ConBalanceDate from dbo.Dat_Contract as cog  group by cog.ConProjId,cog.ConSignDate,cog.ConBalanceDate ) as co
    on   co.ConProjId=p.ProjID   and ConSignDate<='2015-09-22' and  ISNULL(ProjIsDeleted,0)!=1  group by ProjApplyDate,projProperty,ProjID,ProjStatusCurrent,ProjGuId,ProjEtpId,ProjRegionId,ProjName,ProjAddress,ProjAreaSize,ProjCost,ProjCreateTime,ProjChargePerson,ProjChargePersonPhone,ProjApplyEtp,ProjApplyPerson,ProjApplyPersonPhone,ProjConstructEtp,ProjConstructPM,ProjConstructPMPhone,ProjDirector,ProjDirectorPhone,ProjSafeOrgz,ProjCode,ProjIsEnable )as t1

    ) as tt where row_number between 1 and 5


    ---耗时0.01








    SELECT   * FROM(
    SELECT ROW_NUMBER() OVER(ORDER BY  ProjID) as row_number,* FROM (

    select ProjApplyDate,projProperty,ProjID,ProjStatusCurrent,ProjGuId,ProjEtpId,ProjRegionId,ProjName,ProjAddress,ProjAreaSize,ProjCost,ProjCreateTime,ProjChargePerson,ProjChargePersonPhone,ProjApplyEtp,ProjApplyPerson,ProjApplyPersonPhone,ProjConstructEtp,ProjConstructPM,ProjConstructPMPhone,ProjDirector,ProjDirectorPhone,ProjSafeOrgz,ProjCode,ProjIsEnable
    ,min(ConSignDate) as ConSignDate,max(ConBalanceDate) as ConBalanceDate  
    from  dbo.fn_GetProjectsByUserId(100093) as p INNER join dbo.Dat_Contract as co
    on   co.ConProjId=p.ProjID   and ConSignDate<='2015-09-22' and  ISNULL(ProjIsDeleted,0)!=1  group by ProjApplyDate,projProperty,ProjID,ProjStatusCurrent,ProjGuId,ProjEtpId,ProjRegionId,ProjName,ProjAddress,ProjAreaSize,ProjCost,ProjCreateTime,ProjChargePerson,ProjChargePersonPhone,ProjApplyEtp,ProjApplyPerson,ProjApplyPersonPhone,ProjConstructEtp,ProjConstructPM,ProjConstructPMPhone,ProjDirector,ProjDirectorPhone,ProjSafeOrgz,ProjCode,ProjIsEnable )as t1

    ) as tt where row_number between 1 and 5

    --耗时 0.18

  • 相关阅读:
    Flask常用插件
    Mac使用Pyenv管理Python版本
    JS类似于C#中List的Where取FirstOrDefault写法
    MSSQL中Repalce函数处理长字符串时报异常的解决方案
    sqlcmd执行含中文等字符的sql脚本时报错解决方案
    使用7z程序CLI实现基础功能
    VBA中Selection.TypeText长度限制的替代写法
    .Net中Aspose组件调试技巧
    使用Foxit Reader实现批量打印以及一页多版设置技巧
    html2canvas中toDataURL方法返回值为:data,解决方案
  • 原文地址:https://www.cnblogs.com/change4now/p/5665183.html
Copyright © 2020-2023  润新知