SQLServer2008 关于数值字段列的累计

create table #temp20110610
(
     id int identity(1,1),
     date varchar(8),
     qty float
)

insert into #temp20110610
select '20110401',40 union all
select '20110402',64 union all
select '20110403',56 union all
select '20110404',346 union all
select '20110405',56 union all
select '20110406',678 union all
select '20110407',1234 union all
select '20110408',560 union all
select '20110409',460 union all
select '20110410',566 union all
select '20110411',344 union all
select '20110412',77 union all
select '20110413',90

declare @SDate varchar(8),@EDate varchar(8),@conditionQty float
set @SDate='20110405'
set @EDate='20110411'
set @conditionQty=3000
--得到指定日期范围类,Qty列的累积数量大于3000
select id,date,qty,
(select SUM(qty) from #temp20110610 where date<=A.date and date between @SDate and @EDate) Qty累计量
from #temp20110610 A
where (select SUM(qty) from #temp20110610 where date<=A.date and date between @SDate and @EDate)<
=@conditionQty
and date between @SDate and @EDate
order by A.date

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值