我们遇到了在线支付网关系统的问题,有时会在几分钟内重复交易条目。
我们想要创建这些交易的记录,以便我们可以分析和更正它们。
单表,如下。这仅显示一个卡号的结果。我们宁愿只返回同一天发生的交易,最好是在 5 秒之内,就像最后两行一样。
txn_authcode card_number cardtype txn_status txn_value entryTimeStamp
-------------------------------------------------------------------------------
1491109220 ....0279 Visa FAILED 20.00 2011-06-24 19:49:00
1491109219 ....0279 Visa FAILED 20.00 2012-05-28 22:47:57
1491109218 ....0279 Visa FAILED 20.00 2012-05-28 22:46:39
1491109217 ....0279 Visa FAILED 20.00 2012-05-28 22:46:35
到目前为止,我有以下内容,它获取给定卡号的重复记录,但我不确定如何进一步细化此记录,以便在同一天获取记录,最好在 5 秒内获取记录。
select * from(
select t1.txn_authcode,t1.txn_status,t1.txn_value,t1.entryTimeStamp
from transactions t1
where 1=1
and exists
(select null
from transactions t2
where t1.card_number = t2.card_number
and t1.entryTimeStamp <> t2.entryTimeStamp
and t2.entryTimeStamp >= '2012-05-01'
and t2.entryTimeStamp <= '2012-06-01'
--*** AND DATEDIFF ( day , t1.entryTimeStamp , t2.entryTimeStamp ) < 1
--(datediff above doesn't work as it can return a single record for a given card,
--but we only want records that have at least one other transaction record on the same
--day for the same card)
)
and t1.entryTimeStamp >= '2012-05-01'
and t1.entryTimeStamp <= '2012-06-01'
)x
order by card_number,entryTimeStamp desc
有人可以帮我解决这个问题吗?