a表
日期时间 wd yl ll wd1 yl1 ll1 .........
2008-2-15 9:00:00 50 5 300 40 4 200
2008-2-15 10:00:00 60 5 800 50 3 600
2008-2-15 11:00:00 40 5 2000 37 5 1000
.
.
.
.
b表(要得到的结果)
日期时间 ll ll1 .........
2008-2-15 9:00:00 300 200
2008-2-15 10:00:00 500 400
2008-2-15 11:00:00 1200 400
.
.
.
也就是将a表的ll,ll1,....依据日期时间((2008-2-15 10:00:00)-(2008-2-15 9:00:00))
相减得到ll,ll1,.....差值写入b表中,应该怎样写!
多谢大家!!我是初学者!!
日期时间 wd yl ll wd1 yl1 ll1 .........
2008-2-15 9:00:00 50 5 300 40 4 200
2008-2-15 10:00:00 60 5 800 50 3 600
2008-2-15 11:00:00 40 5 2000 37 5 1000
.
.
.
.
b表(要得到的结果)
日期时间 ll ll1 .........
2008-2-15 9:00:00 300 200
2008-2-15 10:00:00 500 400
2008-2-15 11:00:00 1200 400
.
.
.
也就是将a表的ll,ll1,....依据日期时间((2008-2-15 10:00:00)-(2008-2-15 9:00:00))
相减得到ll,ll1,.....差值写入b表中,应该怎样写!
多谢大家!!我是初学者!!
日期时间,
[ll]=ll-isnull((select ll from A where 日期时间=(select max(日期时间) from A where 日期时间<t.日期时间)),0),
[ll1]=ll1-isnull((select ll1 from A where 日期时间=(select max(日期时间) from A where 日期时间<t.日期时间)),0)
from
A t
insert @A select '2008-2-15 9:00:00',300,200
insert @A select '2008-2-15 10:00:00',800,600
insert @A select '2008-2-15 11:00:00',2000,1000 select
日期时间,
[ll]=ll-isnull((select ll from @A where 日期时间=(select max(日期时间) from @A where 日期时间<t.日期时间)),0),
[ll1]=ll1-isnull((select ll1 from @A where 日期时间=(select max(日期时间) from @A where 日期时间<t.日期时间)),0)
from
@A t
(所影响的行数为 1 行)
(所影响的行数为 1 行)
(所影响的行数为 1 行)日期时间 ll ll1
------------------------------------------------------ ----------- -----------
2008-02-15 09:00:00.000 300 200
2008-02-15 10:00:00.000 500 400
2008-02-15 11:00:00.000 1200 400(所影响的行数为 3 行)
declare @A table (日期时间 datetime,ll int,ll1 int)
insert @A select '2008-2-15 9:00:00',300,200
insert @A select '2008-2-15 10:00:00',800,600
insert @A select '2008-2-15 11:00:00',2000,1000
create table b
(
日期时间 datetime,
ll int,
ll1 int
)
insert into b(日期时间,ll,ll1)
select
日期时间,
[ll]=ll-isnull((select ll from @A where 日期时间=(select max(日期时间) from @A where 日期时间<t.日期时间)),0),
[ll1]=ll1-isnull((select ll1 from @A where 日期时间=(select max(日期时间) from @A where 日期时间<t.日期时间)),0)
from
@A t我还有不明白的,就是如何获取a表中的数据而不是
insert @A select '2008-2-15 9:00:00',300,200
insert @A select '2008-2-15 10:00:00',800,600
insert @A select '2008-2-15 11:00:00',2000,1000
兄弟我实在是太笨!!!