加入A表数据如下A(id,tt,time)
insert into B(id,tt)
select X.tt-Y.tt
from A X,A Y
where A.time='2010-7-12 14:00:00'and B.time='2010-7-11 14:00:00' and A.id=B.id
当然时间位置格式不一定正确,可根据需要修改,主要方法是利用表自身的连接,然后用差值运算
insert into t
as
select
sum(case when to_char(dt ,'DD HH24') =
to_char(sysdate -1, 'dd HH24')
then - tt
when to_char(dt ,'DD HH24') = to_char(sysdate , 'dd HH24')
then tt
else 0
end)
from A
where to_char(dt ,'DD HH24') >=
to_char(sysdate -1, 'dd HH24') and to_char(dt ,'DD HH24') <= to_char(sysdate , 'dd HH24')
select * from A where to_char(A.cudate,'yyyy-mm-dd HH24') between
to_char(trunc(sysdate-1)+14/24,'yyyy-mm-dd HH24')
and to_char(trunc(sysdate)+14/24,'yyyy-mm-dd HH24')
这里查出的
今天14点-昨天14点的数据
SELECT * INTO table2 from table1 where time between '时间' and '时间'