日期:2014-05-18 浏览次数:20827 次
create table t346 (年月 date, 货物数量 int) insert into t346 select '2011-1-1', 98 union all select '2011-1-25', 10 union all select '2011-2-3', 13 union all select '2011-3-5', 4 select a.年月, (select isnull(sum(货物数量),0) from t346 b where b.年月<convert(date,a.年月+'-01')) 货物数量 from ( select distinct left(convert(varchar(12),年月,23),7) 年月 from t346 union all select left(convert(varchar(12),dateadd(m,1,max(年月)),23),7) from t346 ) a 年月 货物数量 ------------ ----------- 2011-01 0 2011-02 108 2011-03 121 2011-04 125 (4 row(s) affected)