English 中文(简体)
在加入时,使“平等”与“平等”相同
原标题:Making "close to" the same as "equal" in a join
  • 时间:2012-01-13 23:16:14
  •  标签:
  • sql
  • db2

我在此案中使用了银二,但我对此做了笼统的答复。 我对数据做了与我一样的简化。 我期待大家采取行动,处理所谓的“索赔”。 每项索赔都有独特的索赔号。 每项行动都以“hmm”的形式发生。 实际上,我不计行动,我算起行动会议——时间最晚,一个人就一项索赔采取行动,那是一次行动。 但是,有时一个人对一项索赔采取多种行动,被几秒或几分钟分开:这也是一次行动。 但是,如果有人在10am对一项索赔采取行动,然后在1时就同一索赔采取行动,那将是两次行动。 就我而言,一次行动会议对两次行动会议而言,时间之窗是3小时,当然是任意的。 夜晚间,窗户无担忧。 而且,我仅读取这一数据,我不得不在一份发言中这样做。 感谢。

So 这里的一些数据(表格:行动):

CLAIM_NO ACTTIME
AA       1424
BB       1134
CC       1221
DD       1425
DD       1512
EE       1619
FF       0928
FF       1518
GG       1348
HH       1332
II       1350

我愿把这一点变为现实。

CLAIM_NO ACTTIME
AA       1424
BB       1134
CC       1221
DD       1425
EE       1619
FF       0928
FF       1518
GG       1348
HH       1332
II       1350

(注意到第二个DD记录已经过去,但第二个FF记录仍然存在)。

我完成了这项工作,将索赔表提交给了自己。 无平等,ACTTIM在3小时前和1分钟之前。 这使我能够接手不归属的囚室,然后我利用EXCEPT去除。

with excepto as (
 select a.claim_no, b.acttime
 from actions a 
 join actions b
 on a.claim_no=b.claim_no 
  and a.acttime between (b.acttime-300) and (b.acttime-1)
)
select * from actions except select * from excepto

但我要与大家一道这样做,因此没有必要“例外”。 我们希望,业绩会更好:我的真实数据当然会有更多的专栏被除子和更多行使用。 除发言外,这似乎减缓了整个问题。 采用“附有”说明的整批临时表格的Im,似乎比其部分的总和要慢得多。

最佳回答

我对忘记这一点感到sil笑。

页: 1

SELECT a.claim_no, a.acttime
FROM actions as a
EXCEPTION JOIN actions as b
ON b.claim_no = a.claim_no
AND b.acttime >= a.acttime - 300
AND b.acttime < a.acttime

取得以下成果:

claim_No     acttime
============================
AA           1,424 
BB           1,134 
CC           1,221 
DD           1,425 
EE           1,619 
FF             928 
FF           1,518 
GG           1,348 
HH           1,332 
II           1,350 

(很幸运的是,如果你有些人每3小时至少做一次改变,那就没有这样做了——它只能显示头一次。) 我认为,你需要像一个6条轨道的自我参与最低>,以发现适当的条目,而且这种条目也多少有点被混淆;你可能更愿意处理这一申请方。

问题回答

假定行为时间为一栏:

select *
from (
   select claim_no,
          acttime, 
          acttime - lag(acttime, 1, acttime) over (partition by claim_no order by acttime) as diff
   from actions
) t
where diff = 0 or diff > 300
order by claim_no




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...