TRY:
select l.本月工资 ,sum(msx(r.本月工资)) as 本月止累计工资,l.时间
from table l
join table r
on l.时间 >= r.时间 
group by l.本月工资,l.时间

解决方案 »

  1.   

    TRY:select l.本月工资 ,sum(max(r.本月工资)) as 本月止累计工资,l.时间
    from table l
    join table r
    on l.时间 >= r.时间 
    group by l.本月工资,l.时间
      

  2.   

    declare @ table (本月工资 int,时间 datetime)
    insert @ values('01','2002-1-3')
    insert @ values('02','2002-2-3') 
    insert @ values('11','2003-2-3')
    insert @ values('22','2003-3-3')
    insert @ values('33','2003-4-3')select 本月工资,isnull((select sum(本月工资) from @ b where 时间<=a.时间 and 
    exists(select 1 from @ where datediff(month,时间,b.时间)=1 and datediff(month,时间,a.时间)=1 )),本月工资) 本月止累计工资,
    时间 from @ a
      

  3.   

    declare @l table (salary int, mon datetime )
    insert @l values (1  ,'2002-1-3')
    insert @l values (2  ,'2002-2-3')
    insert @l values (11 ,'2003-2-3')
    insert @l values (22 ,'2003-3-3')
    insert @l values (33 ,'2003-4-3')
    select l.salary , sum(r.salary) as amount , l.mon
    from  @l as l
    inner join  @l as r on l.mon >= r.mon
    group by l.salary,l.mon
      

  4.   

    create table tab1  (本月工资 int,时间 datetime)
    insert tab1 values('01','2002-1-3')
    insert tab1 values('02','2002-2-3') 
    insert tab1 values('11','2003-2-3')
    insert tab1 values('22','2003-3-3')
    insert tab1 values('33','2003-4-3')
    select t.本月工资,s.本月止累计工资,s.时间 from tab1 t inner join (select l.时间,sum(r.本月工资)AS 本月止累计工资
    from tab1 l
    join tab1 r
    on l.时间 >= r.时间 and year(l.时间)=year(r.时间)
    group by l.时间) s on t.时间=s.时间这样肯定是对的,我在SQL 查询分析器中调试过了。