create table #tmp1
( id int,
datetime datetime,
code int,
name varchar(200),
bid float
)
create index idx_#tmp1 on #tmp1(datetime,code)insert into #tmp1
select 142425 , '2006-4-28 10:53:00', 1, '铜', 67300
union select 141819 , '2006-4-27 10:58:00', 2, '锡', 85000
union select 141817 , '2006-4-27 10:58:00', 1, '铜', 69550
union select 141191 , '2006-4-26 10:57:00', 2, '锡', 84500
union select 141177 , '2006-4-26 10:52:00', 1, '铜', 68000 --select * from #tmp1
select a.id,a.datetime,a.code,a.name,isnull(a.bid - b.bid,0)
from #tmp1 a left join #tmp1 b on convert(varchar,a.datetime,112) = dateadd(day,1,convert(varchar,b.datetime,112)) and a.code = b.code
( id int,
datetime datetime,
code int,
name varchar(200),
bid float
)
create index idx_#tmp1 on #tmp1(datetime,code)insert into #tmp1
select 142425 , '2006-4-28 10:53:00', 1, '铜', 67300
union select 141819 , '2006-4-27 10:58:00', 2, '锡', 85000
union select 141817 , '2006-4-27 10:58:00', 1, '铜', 69550
union select 141191 , '2006-4-26 10:57:00', 2, '锡', 84500
union select 141177 , '2006-4-26 10:52:00', 1, '铜', 68000 --select * from #tmp1
select a.id,a.datetime,a.code,a.name,isnull(a.bid - b.bid,0)
from #tmp1 a left join #tmp1 b on convert(varchar,a.datetime,112) = dateadd(day,1,convert(varchar,b.datetime,112)) and a.code = b.code
解决方案 »
- 求助,关于取数的问题?
- 计算增长率
- 执行 exec sp_fulltext_database N'enable' 语句时出现"未安装全文检索或未能装载某一全文组件。"错误信息,要安装什么组件?
- SQL查询
- 请问,如何恢复数据库?
- 在DELPHI中调用带参数的存储过程
- SQL2005replciation中publisher端表加一字段,在publication的article中会自动加上该新字段并打上钩,如何避免?另一贴100分一起结。
- DTS是什么?有什么用?怎样用?
- 为什么会有这个问题出现?!update select 的
- 这段触发器程序错在哪里?
- SQL Server 对称加密 导出的文件 如何解密
- SQL语句用了关键字DISTINCT,还能用关键字TOP吧?
142425 2006-4-28 10:53:00 1 铜 67300
141819 2006-4-27 10:58:00 2 锡 85000
141817 2006-4-27 10:58:00 1 铜 69550
141191 2006-4-26 10:57:00 2 锡 84500
141177 2006-4-26 10:52:00 1 铜 68000分组求铜,锡4月最初价格,最后价格,平均价格这个怎么搞谢谢了