所有记录彼此相隔x分钟 [英] All records within x minutes of each other

查看:53
本文介绍了所有记录彼此相隔x分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个包含用户/机器的Internet浏览历史记录的表,

日期/时间到分钟。目标是将以前和随后的时间分隔的所有时间标记为x分钟或更短的时间(它可能会变化,并且不一定是
。一个方便的圆数)。这将

启用报告活动时间对于用户来说(一个可疑的推断,但是嘿)。


有很多衍生方式可以看到这些信息,这可能是很好的。这些次数的拳头和最后一次是什么?什么

给定时期的百分比是按活动时间划分的,而不是?

这些期间的平均持续时间是多少?

网络点击期间的平均间隔是多少?在其他时间?


Blah,等等。基本问题是我的主要问题。我没有太多使用游标的经验,但根据我的理解,这将是非常好的

确实可以节省它们,考虑到我预计工作的记录数量

with。


我会很高兴有任何指示。


-


Scott

Consider a table that holds Internet browsing history for users/machines,
date/timed to the minute. The object is to tag all times that are separated
by previous and subsequent times by x number of minutes or less (it could
vary, and wouldn''t necessarily be a convenient round number). This will
enable reporting "active time" for users (a dubious inference, but hey).

There are a lot of derivative ways of seeing this information that might be
good to get to. What''s the fist and last of these sets of times? What
percentage of a given period is spanned by active times, and not? What is
the average duration of such periods? What is the average interval between
web hits during such periods? During other times?

Blah, blah. The basic problem is my principal problem. I don''t have much
experience with cursors, but from what I understand it would be very good
indeed to spare them, given the number of records I anticipate working
with.

I''d be glad of any pointers.

--

Scott

推荐答案

基础知识:时间来自持续时间,因此evetns有一个开始和停止时间。

真正好的东西可以在亚利桑那大学

网站上找到,他们有一份Rick Snodgrass书和他的

研究论文的PDF副本。 br />
Basics: Time comes in durations, so evetns have a start and stop time.
The really good stuff can be found at the University of Arizona
website where they have a PDF copy of the Rick Snodgrass book and his
research paper.


有很多方法可以实现这一点,例如:


得到一组活动期的开头:


选择......

来自不存在的事件(

----前面没有事件......分钟



并存在(

----以下活动......分钟




获得一系列活跃期间的结局:


选择...

来自不存在的事件(

----以下没有活动......分钟



并且存在(

----前面的事件...分钟




完成后,你需要将每个开头都匹配到相应的结尾。

使用SQL 2005中提供的row_number()非常简单

在早期版本中,您可以使用

identity()列模拟row_number()结果集,或使用这样的连接条件:


....

从开头b加入结束e在b.time< e.time

哪里不存在(从b1开始选择1,其中b.time< b1.time和

b1.time< e.time)

且不存在(从结尾e1中选择1,其中b.time< e1.time和

e1.time< e.time)

There are many way to accomplish this, for instance:

get a set of beginnings of active periods:

select ...
from events where not exists(
---- no events in the preceding ... minutes
)
and exists(
---- events in the followinging ... minutes
)

get a set of endings of active periods:

select ...
from events where not exists(
---- no events in the following ... minutes
)
and exists(
---- events in the preceding ... minutes
)

That done, you need to match every beginning to its corresponding end.
This is very simple using row_number() available in SQL 2005
In earlier versions, you can either emulate row_number() using
identity() column in a result set, or use a join condition like this:

....
from beginnings b join ends e on b.time<e.time
where not exists(select 1 from beginnings b1 where b.time< b1.time and
b1.time<e.time)
and not exists(select 1 from endings e1 where b.time< e1.time and
e1.time<e.time)


2005年8月30日13:28:36 -0700, - CelKO--写道:
On 30 Aug 2005 13:28:36 -0700, --CELKO-- wrote:
基础知识:时间来自持续时间,因此evetns有一个开始和停止时间。
真正好的东西可以在亚利桑那大学的网站上找到他们有一本Rick Snodgrass书的PDF副本和他的
研究论文。
Basics: Time comes in durations, so evetns have a start and stop time.
The really good stuff can be found at the University of Arizona
website where they have a PDF copy of the Rick Snodgrass book and his
research paper.




Joe,没有判断你的基本断言时间进来了

持续时间,你必须意识到网络请求,就像在
计算中的大多数其他事件一样,不会记录为持续时间,而是记录为瞬间。除非你打算在这个星球上赢得每个网络服务器的作者和管理员,否则我们将不得不将它们作为事件进行交易,不是
持续时间。



Joe, without passing judgement on your basic assertion "Time comes in
durations", you must be aware that web requests, like most other events in
computing, are not ever logged as durations, but as instants. Unless you
intend to win over the writers and administrators of every web server on
the planet, we''re going to have to damn well DEAL with them as events, not
durations.


这篇关于所有记录彼此相隔x分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆