Mysql 识别SQL中的重复事务
最近由于一个问题,在不同的时间将多个重复事务插入数据库。需要找到那些重复的事务并删除它们 我尝试对成员和事务进行分组Mysql 识别SQL中的重复事务,mysql,sql,Mysql,Sql,最近由于一个问题,在不同的时间将多个重复事务插入数据库。需要找到那些重复的事务并删除它们 我尝试对成员和事务进行分组 select count(*), member_id, TRUNC(created, 'DDD') from TXN where created > TO_DATE('06/01/2019 00:00:00', 'MM/DD/YYYY HH24:MI:SS') group by member_id,
select count(*),
member_id,
TRUNC(created, 'DDD')
from TXN
where created > TO_DATE('06/01/2019 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
group by member_id,
TRUNC(created, 'DDD')
having count(*) > 2;
我需要在10分钟的时间差内为同一成员创建的所有事务
示例:
在本例中,我需要前两个TXN作为输出,因为如果时差不超过10分钟,并且具有相同的成员编号,您可能需要自联接:
对于TNX中的每条记录,您提供其副本。如果要删除这些事务:
delete tnext
from txn tnext join
txn t
on tnext.member_id = t.member_id and
tnext.created > t.created and
tnext.created < t.created + interval 10 minute
where t.created > '2019-06-01';
请问TXN的结构是什么?哪些交易是重复的当且仅当它们具有相同的成员id时才是重复的交易?你能提供一些TXN中交易记录的例子吗?@DmitryBychenko在TXN表中我有唯一的成员id来找到重复的。我可以使用的一件事是它创建的时间,通常不超过10分钟的时差。你能给出一些你想要的输入和输出示例吗?提供示例感谢你给我时间。通过这一个,我得到的结果有重复的行ID和重复的创建。。。。。所有内容都为空。@Addala Shivateja:很抱歉,它必须是内部联接,而不是左联接:我们不希望得到没有重复项的记录
select a.Member_Id as Member_Id,
a.Row_Id as Row_Id,
a.Org as Org,
a.Dest as Dest ,
a.Created as Created,
b.Row_Id as Duplicate_Row_Id,
b.Org as Duplicate_Org,
b.Dest as Duplicate_Dest,
b.Created as Duplicate_Created
from TXN a inner join
TXN b on a.Member_Id = b.Member_Id and
a.Created < b.Created and
TIMESTAMPDIFF(a.Created, b.Created) / 60 <= 10
order by a.Member_Id
delete tnext
from txn tnext join
txn t
on tnext.member_id = t.member_id and
tnext.created > t.created and
tnext.created < t.created + interval 10 minute
where t.created > '2019-06-01';
select t.*
from txn t
where not exists (select 1
from t tprev
where tprev.member_id = t.member_id and
tprev.created < t.created and
tprev.created > t.created - interval 10 minute
) and
t.created >= '2019-06-01';