orcale 如何查询半小时内满足条件的记录。

例如查询出银行柜员半小时内办理开户业务超过5笔的记录(从每日流水表了抽取数据)。

压根没人回答啊。尴尬了我的 哥哥。。。。。

你这个半小时,需要有个基准时间啊,参考这个语句,这是查询当前时间三十分钟内得数据:
select * from table where up_time >= sysdate-30/(24*60) and up_time<sysdate

这个方法的思路是取出任意两个数据间隔差为5的两条数据,判断添加时的时差是否大于30分钟

//1.原始表数据
select t.* from ceshi t order by t.ctime
图片说明
//2.按时间排序(正序)增加序列
select Row_Number() over ( order by ctime ) as xulie , t.ctime from ceshi t
图片说明
//3根据序列自关联查询任意两条数据插入间隔差为5的数据,组成一个新表
select c1.xulie xulie1,c1.ctime ctime1,c2.xulie xulie2,c2.ctime ctime2 from
(select Row_Number() over ( order by ctime ) as xulie , t.ctime from ceshi t) c1
left join
(select Row_Number() over ( order by ctime ) as xulie , t.ctime from ceshi t) c2
on
c1.xulie +4 = c2.xulie
图片说明
//4.根据生成的这个新表,查询出时间间隔差大于30分钟的数据

select * from (
select c1.xulie xulie1,c1.ctime ctime1,c2.xulie xulie2,c2.ctime ctime2 from
(select Row_Number() over ( order by ctime ) as xulie , t.ctime from ceshi t) c1 left join
(select Row_Number() over ( order by ctime ) as xulie , t.ctime from ceshi t) c2 on
c1.xulie +4 = c2.xulie
) t2 where t2.ctime2-ctime1>30/(24*60)
图片说明
//5.查时间间隔差大于30分钟的数据的总数
select count(xulie1) from (
select c1.xulie xulie1,c1.ctime ctime1,c2.xulie xulie2,c2.ctime ctime2 from
(select Row_Number() over ( order by ctime ) as xulie , t.ctime from ceshi t) c1 left join
(select Row_Number() over ( order by ctime ) as xulie , t.ctime from ceshi t) c2 on
c1.xulie +4 = c2.xulie
) t2 where t2.ctime2-ctime1>30/(24*60)
图片说明
//现在就可以根据总数是否大于0判断柜员是否有违规操作了,OK,大功告成!
测试用的比较简单的表,不知道实际对于大量数据查询效率如何!

真是有心了。入行不久,最近也开始学习ROW__NUMBER函数处理连续性的问题。我用的row_number 函数分区后处理柜员连续几笔业务是否是同一类型的业务。
这个问题我也解决了。思路和你的这个思路差不多。不过我用的是LEAD函数。参考了这个方法。http://blog.itpub.net/24496749/viewspace-723170/
非常感谢你的用心回复。像你学习了。

另外我没有用left join 我用的是直接关联查询。具体他们之间有什么差别。我也不是很清楚。还请指正。