--我的为什么不行?--创建数据测试环境
declare @库存表a table(KehuId int,Date varchar(6),Count int)
insert into @库存表A
select 1,'200304',1000
union all select 1,'200305',2000
union all select 1,'200306',2500
union all select 2,'200304',3000
union all select 2,'200305',4000declare @库存表B table(KehuId int,Date varchar(6),LastCount int,NewCount int)--插入当月统计数量
insert into @库存表B(KehuId,Date,NewCount,LastCount)
select KehuId,Date,Count
,(select top 1 Count from @库存表A where KehuId=a.KehuId and Date<a.Date order by Date desc)
from @库存表A a--显示处理结果
select * from @库存表B
declare @库存表a table(KehuId int,Date varchar(6),Count int)
insert into @库存表A
select 1,'200304',1000
union all select 1,'200305',2000
union all select 1,'200306',2500
union all select 2,'200304',3000
union all select 2,'200305',4000declare @库存表B table(KehuId int,Date varchar(6),LastCount int,NewCount int)--插入当月统计数量
insert into @库存表B(KehuId,Date,NewCount,LastCount)
select KehuId,Date,Count
,(select top 1 Count from @库存表A where KehuId=a.KehuId and Date<a.Date order by Date desc)
from @库存表A a--显示处理结果
select * from @库存表B
解决方案 »
- EXCEL导入SQL SERVER2000问题。。。纠结
- 请教查询分析器登录不了,而企业管理器可以登录的问题
- 这个存储过程如何写?
- 对高手来说是非常简单的问题:把insert写在存储过程里用与在程式中直接用insert语句怎么会有这个区别?
- 用ISS文件安装MSDE/SQL SERVER,如何设置服务在开机时自动启动?
- 请教!关于使用“可变长度数据类型”的问题
- 请问textcopy的使用
- openrowset问题
- 如何写这样要求的SQL呀?各位帮帮忙呀
- 关于如何的到数据库中表的结构的问题(刚才已经为此送了200分了,友情再放送20分,:))
- 请你进来看看这个SQL如何写?先谢了。
- 请问怎么能把mysql数据库转换为sql server数据库
例如,假设表中有如下记录:
1 200304 1400
1 200304 2400
1 200305 1400那200305的LastCount是多少?