作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这样的 table
你会看到红十字签名就是我想要的结果。我想将红十字签名移至错误日志表,因为它指示重复的数据。
确定数据是否重复:
示例:
1545981655
1545981657 x -> will marked as duplicate because 1545981657 - 60 = 1545981597. Search first data > 1545981597 except this line. 1545981655 will return.
1545981660 x -> will marked as duplicate because 1545981660 - 60 = 1545981600. Search first data > 1545981600 except this line. 1545981655 will return.
1545981662 x -> will marked as duplicate because 1545981662 - 60 = 1545981602. Search first data > 1545981602 except this line. 1545981655 will return.
1545981707 -> won't marked as duplicate because 1545981707 - 60 = 1545981647. Search first data > 1545981647 except this line. 1545981655 won't return because publisher_asset_id is different.
1545981710 x -> will marked as duplicate because 1545981710 - 60 = 1545981650. Search first data > 1545981650 except this line. 1545981707 will return.
1545981712 x -> will marked as duplicate because 1545981712 - 60 = 1545981652. Search first data > 1545981650 except this line. 1545981707 will return.
1545981714 x -> will marked as duplicate because 1545981714 - 60 = 1545981654. Search first data > 1545981654 except this line. 1545981707 will return.
1545981718 -> won't marked as duplicate because 1545981718 - 60 = 1545981658. Search first data > 1545981658 except this line. No data returns, because pubisher_asset_id is different
如何在 mysql 查询语句中实现此目的,而不是循环整个数据?
我想达到这样的结果:
需要你们的帮助。非常感谢。
最佳答案
将表 T 重命名为您的表并尝试以下操作:
SELECT * FROM (
SELECT id, advertiser_id, offer_id, commission_id, commission_tier_id, creative_id, publisher_id, publisher_asset_id, source_id, impression_timestamp,
COUNT(*) OVER (PARTITION BY advertiser_id, offer_id, commission_id, commission_tier_id, creative_id, publisher_id, publisher_asset_id, source_id ORDER BY impression_timestamp RANGE 60 PRECEDING) AS DuplicateFlag
FROM T
) DetectDuplicate
WHERE DuplicateFlag > 1
编辑:在 MySQL 8 之前,上面的查询无法完成,必须替换为带有 JOIN 的查询(不幸的是有点慢):
SELECT DISTINCT T2.*
FROM T T1
LEFT OUTER JOIN T T2
ON T1.id <> T2.id
AND T1.advertiser_id = T2.advertiser_id
AND T1.offer_id = T2.offer_id
AND T1.commission_id = T2.commission_id
AND T1.commission_tier_id = T2.commission_tier_id
AND T1.creative_id = T2.creative_id
AND T1.publisher_id = T2.publisher_id
AND T1.publisher_asset_id = T2.publisher_asset_id
AND T1.source_id = T2.source_id
AND T1.impression_timestamp >= T2.impression_timestamp - 60
WHERE T2.id IS NOT NULL
至少还有一种其他语法是可能的,例如:
SELECT *
FROM T Main
WHERE EXISTS (
SELECT 1
FROM T
WHERE id <> Main.id
AND advertiser_id = Main.advertiser_id
AND offer_id = Main.offer_id
AND commission_id = Main.commission_id
AND commission_tier_id = Main.commission_tier_id
AND creative_id = Main.creative_id
AND publisher_id = Main.publisher_id
AND publisher_asset_id = Main.publisher_asset_id
AND source_id = Main.source_id
AND impression_timestamp >= Main.impression_timestamp - 60
)
关于mysql - 如何检查MySQL中的每一行(时间戳 - 60秒)以确定是否存在重复数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54068375/
给定一个带有多个 date_time 戳的字符串,我想 提取第一个戳及其前面的文本 候选字符串可以有一个或多个时间戳 后续的 date_time 戳记将被 sep="-" 隔开 后续date_time
是否可以合并从相机拍摄的文本和照片?我想在照片上标记日期和时间,但我在 Google 上找不到任何内容。 最佳答案 使用下面的代码来实现你所需要的。 Bitmap src = Bitm
有没有办法通过 Graph API 戳另一个用户?基于this post ,并使用 Graph Explorer ,我发布到“/USERID/pokes”,我已经授予它(Graph API 应用程序和
我有两个向左浮动的元素。一个是 body 的第一个 child ,另一个是容器的第一个 child ,容器是 body 的第二个 child 。 ...
我是一名优秀的程序员,十分优秀!