select a.month, a.goods, sum(b.num )
from table a ,table b
where b.month <= a.month
and a.goods = b.goods
and a.month = '2'
group by a.shangping;
from table a ,table b
where b.month <= a.month
and a.goods = b.goods
and a.month = '2'
group by a.shangping;
from table a ,table b
where b.month <= a.month
and a.goods = b.goods
and a.month = '2'
group by a.goods,a.month;
(select yf,sp,sum(sl)sl from a group by sp,yf)a,
(select sp,sum(sl)ljsl from a group by sp)b
where a.yf=2 and a.sp=b.sp
tabl t1
(select 商品,sum(数量) as 累计数量 from tabl group by 商品) t2
where t1.商品=t2.商品;
select 月份,商品,数量,sum(数量)over(group by 月份,商品)累计数量 from 销售表 order by 月份,商品
to: shahand, 月份不止只有2月份。
如果有3月,4月,5月呢,月份不固定。
用一条sql语句统计2月份的数据,并且加一个累计数量(累计本年的全部数量)
如果你想要所有月份的:
select a.yf,a.sp,a.sl,ljsl from
(select yf,sp,sum(sl)sl from a group by sp,yf)a,
(select sp,sum(sl)ljsl from a group by sp)b
where a.sp=b.sp
:)
不通过。
http://expert.csdn.net/Expert/topic/1762/1762077.xml?temp=.3312647