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