[英]MySQL delete entries based on last two digits of Unix/Epoch time
I have a table with three columns: 我有一个包含三列的表:
`id` int(11) NOT NULL auto_increment
`tm` int NOT NULL
`ip` varchar(16) NOT NULL DEFAULT '0.0.0.0'
I want to run a query that will check if the same IP was logged within a minute and then delete all but one of those entries. 我想运行一个查询,该查询将在一分钟内检查是否记录了相同的IP,然后删除其中一个条目之外的所有条目。
For example I have the two rows below. 例如,我有下面两行。
id=1 tm=1361886629 ip=192.168.0.1
id=2 tm=1361886630 ip=192.168.0.1
I would only like to keep one in the database. 我只想在数据库中保留一个。
I have read lots of other remove duplicate/partial duplicate entry questions but I'm looking for a way to compare the last two digits of the Unix/epoch time and delete all but one based on that plus the IP. 我已经阅读了许多其他删除重复项/部分重复项的问题,但我正在寻找一种方法来比较Unix /纪元时间的最后两位,并删除除此以外的所有数字和IP。
Any help is much appreciated. 任何帮助深表感谢。
you can use CAST
in mysql to remove the last 2 digits 您可以在mysql中使用
CAST
删除最后2位数字
SELECT CAST( tm AS CHAR( 8 ) )
this will select only the first 8 digits from the timestamp and allow you to find duplicates 这将仅选择时间戳的前8位数字,并允许您查找重复项
if you only want to know what the last 2 digits are 如果您只想知道最后两位数字是什么
SELECT RIGHT(CAST( tm AS CHAR( 10 ) ), 2)
this will select the last two digits only from each timestamp 这将仅从每个时间戳中选择最后两位数字
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.