695
社区成员
发帖
与我相关
我的任务
分享
--查询语句
select month,sum(sales) as sales
from sales
where year = 2012 and month between @monthfrom and @monthto
group by month
order by month/*order by 这里很关键,因为RunningValue是在一个group范围内,将上一条记录的值累加到本条,所以顺序很关键。上面的nothing 表示全局范围。如果你想在某个group的范围内进行累加,可以把nothing 改成 “GroupName”*/
select sum(sales)
from sales
where year = 2012 and month <= @month and @month=2
union all
select b
from sales
where year = 2012 and month <= @month and @month=1