首页 > 数据库技术 > 详细

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

时间:2016-07-12 23:11:06      阅读:447      评论:0      收藏:0      [点我收藏+]

分组:
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

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

原文:http://www.cnblogs.com/change4now/p/5665183.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!