码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2016-07-12 23:13:36      阅读:275      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!