首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

,关于过去10分钟数据累加

2013-11-14 
求助,关于过去10分钟数据累加数据如下,STATIONID是站名,OBSTIME是观测时间,RAINFALL是一分钟雨量,现在要计

求助,关于过去10分钟数据累加
数据如下,STATIONID是站名,OBSTIME是观测时间,RAINFALL是一分钟雨量,现在要计算每个站每个观测时间前10分钟的累计雨量,并在RAINFALL后加一列RAINFALL10M,把数据插入。如果表中再插入数据,
如52013/7/1 0:41:002013/7/1 0:41:009.00 ,怎么能自动完成上述要求?
小弟刚接触ORACLE,看了很多帖子,还是搞不定,求助各位大神。万分感谢!
STATIONID  OBSTIME      INSERTTIME    RAINFALL    
12013/7/1 0:01:002013/7/1 0:05:001.00
12013/7/1 0:02:002013/7/1 0:05:001.00
12013/7/1 0:03:002013/7/1 0:05:001.00
12013/7/1 0:04:002013/7/1 0:05:001.00
12013/7/1 0:05:002013/7/1 0:05:001.00
12013/7/1 0:06:002013/7/1 0:11:002.00
12013/7/1 0:07:002013/7/1 0:11:002.00
12013/7/1 0:08:002013/7/1 0:11:002.00
12013/7/1 0:09:002013/7/1 0:11:002.00
12013/7/1 0:10:002013/7/1 0:11:002.00
22013/7/1 0:11:002013/7/1 0:17:003.00
22013/7/1 0:12:002013/7/1 0:17:003.00
22013/7/1 0:13:002013/7/1 0:17:003.00
22013/7/1 0:14:002013/7/1 0:17:003.00
22013/7/1 0:15:002013/7/1 0:17:003.00
22013/7/1 0:16:002013/7/1 0:21:004.00
22013/7/1 0:17:002013/7/1 0:21:004.00
22013/7/1 0:18:002013/7/1 0:21:004.00
22013/7/1 0:19:002013/7/1 0:21:004.00
22013/7/1 0:20:002013/7/1 0:21:004.00
32013/7/1 0:21:002013/7/1 0:26:005.00
32013/7/1 0:22:002013/7/1 0:26:005.00
32013/7/1 0:23:002013/7/1 0:26:005.00
32013/7/1 0:24:002013/7/1 0:26:005.00
32013/7/1 0:25:002013/7/1 0:26:005.00
32013/7/1 0:26:002013/7/1 0:30:006.00
32013/7/1 0:27:002013/7/1 0:30:006.00
32013/7/1 0:28:002013/7/1 0:30:006.00
32013/7/1 0:29:002013/7/1 0:30:006.00
32013/7/1 0:30:002013/7/1 0:30:006.00
42013/7/1 0:31:002013/7/1 0:36:007.00
42013/7/1 0:32:002013/7/1 0:36:007.00
42013/7/1 0:33:002013/7/1 0:36:007.00
42013/7/1 0:34:002013/7/1 0:36:007.00
42013/7/1 0:35:002013/7/1 0:36:007.00
42013/7/1 0:36:002013/7/1 0:40:008.00
42013/7/1 0:37:002013/7/1 0:40:008.00
42013/7/1 0:38:002013/7/1 0:40:008.00
42013/7/1 0:39:002013/7/1 0:40:008.00
42013/7/1 0:40:002013/7/1 0:40:008.00













累加?
[解决办法]
楼主能不能说清楚地点,你给的这个数据貌似很巧,每个站点都是10分钟的量。
[解决办法]
select STATIONID,OBSTIME,INSERTTIME,RAINFALL,sum(RAINFALL) over(partition by STATIONID order by OBSTIME range between 1/144 preceding and 0 following) RAINFALL10M from table
[解决办法]
昨天写的乱七八糟,重新写过

update t1 set t1.rainfall10m=(
SELECT sum(rainfall) from t1 t2 WHERE t2.obstime between t1.obstime-1/24/60 and t1.obstime and t1.stationid=t2.stationid
)

[解决办法]
t2也是t1,相当于是引用了一个表两次,t2是起的别名
[解决办法]
引用:
Quote: 引用:

Quote: 引用:

Quote: 引用:

select STATIONID,OBSTIME,INSERTTIME,RAINFALL,sum(RAINFALL) over(partition by STATIONID order by OBSTIME range between 1/144 preceding and 0 following) RAINFALL10M from table


试了一下,可以得出10分钟累加的雨量,不过想要插入rainfall10m的时候(我用的update table set rainfall10m = ,不知道对不对)提示ORA-00913值过多,求解?


update table m set rainfall10 = (select ****** from table where table.****=m.***** and table.****=m.*****)

PS:3楼那是对的。就一个表



按照你说的,我这样写不知道对不对,这样的结果是rainfallm10更新的不是10分钟累加的量,只是前面rainfall的一分钟的量。求助,谢谢。
update table m set rainfallm10 =
(select 
sum(rainfall ) over
(partition by stationid order by obstime range between 9/1440 preceding and 0 following) rainfallm10 from table 
where table.Stationid = m.stationid 
 and table.Obstime = m.obstime
 ) ;

rows  between  10 preceding  and   current  row 
可以不

热点排行