Select Flux,identity(int,1,1) as 'ID'
into #  
from [EP_Flux] 
where  Date >= @StartDate  
       and Date <= @EndDate  
       and CrossingID = @CrossingIDselect (ID-1)/@Flag 
       ,sum(Flux)
from #
group by (ID-1)/@Flag

解决方案 »

  1.   

    create procedure [StatFlux]
    @StartDate datetime,
    @EndDate datetime,
    @CrossingID int = 0,
    @Flag       int =0
    as
    SET NOCOUNT ON
    select @StartDate=isnull(@StartDate,getdate())
           ,@EndDate=isnull(@EndDate,getdate())Select Flux,identity(int,1,1) as 'ID'
    into #  
    from [EP_Flux] 
    where  Date >= @StartDate  
           and Date <= @EndDate  
           and CrossingID = @CrossingIDselect ID+1 as 'ID'
           ,Flux
    from (
            select (ID-1)/@Flag as 'ID'
                   ,sum(Flux) as 'Flux'
            from #
            group by (ID-1)/@Flag
         )t
    order by IDdrop table #SET NOCOUNT OFF