Hi,
The version of MySQL database is 5.5.62
On my MySQL table I need check if the TIMEDIFF() between two rows is greater than the value three minutes
If the TIMEDIFF() is less I update the columns xDisabled with 1 value
This is my table
+------+---------------------+---------+-----------+
| xID | xDate_xHourMinute | xLines | xDisabled |
+------+---------------------+---------+-----------+
| 1405 | 2020-06-21 05:24:19 | 3018122 | |
| 1424 | 2020-06-21 05:22:53 | 3018122 | |
| 1462 | 2020-06-21 05:22:03 | 3018122 | |
| 1473 | 2020-06-21 05:18:59 | 3018122 | |
| 1481 | 2020-06-21 05:18:03 | 3018122 | |
+------+---------------------+---------+-----------+
5 rows in set
I have tried without success this sql query because all rows on the table are updated
UPDATE `xMinutesSet` a
JOIN `xMinutesSet` b ON a.xLines = B.xLines
AND TIMEDIFF(
a.xDate_xHourMinute,
b.xDate_xHourMinute
) < 3
SET a.xDisabled = 1;
+------+---------------------+---------+-----------+
| xID | xDate_xHourMinute | xLines | xDisabled |
+------+---------------------+---------+-----------+
| 1405 | 2020-06-21 05:24:19 | 3018122 | 1 |
| 1424 | 2020-06-21 05:22:53 | 3018122 | 1 |
| 1462 | 2020-06-21 05:22:03 | 3018122 | 1 |
| 1473 | 2020-06-21 05:18:59 | 3018122 | 1 |
| 1481 | 2020-06-21 05:18:03 | 3018122 | 1 |
+------+---------------------+---------+-----------+
5 rows in set
I need this return
+------+---------------------+---------+-----------+
| xID | xDate_xHourMinute | xLines | xDisabled |
+------+---------------------+---------+-----------+
| 1405 | 2020-06-21 05:24:19 | 3018122 | 1 | 00:01:26
| 1424 | 2020-06-21 05:22:53 | 3018122 | 1 | 00:00:50
| 1462 | 2020-06-21 05:22:03 | 3018122 | | 00:03:04
| 1473 | 2020-06-21 05:18:59 | 3018122 | 1 | 00:00:56
| 1481 | 2020-06-21 05:18:03 | 3018122 | |
+------+---------------------+---------+-----------+
5 rows in set
How to do resolve this? Please, any suggestion
My table below
DROP TABLE IF EXISTS `xminutesset`;
CREATE TABLE `xminutesset` (
`xID` int(11) NOT NULL AUTO_INCREMENT,
`xDate_xHourMinute` datetime DEFAULT NULL,
`xLines` varchar(255) DEFAULT NULL,
`xDisabled` int(1) DEFAULT NULL,
PRIMARY KEY (`xID`)
) ENGINE=InnoDB;
-- ----------------------------
-- Records of xminutesset
-- ----------------------------
INSERT INTO `xminutesset` VALUES ('1405', '2020-06-21 05:24:19', '3018122', null);
INSERT INTO `xminutesset` VALUES ('1424', '2020-06-21 05:22:53', '3018122', null);
INSERT INTO `xminutesset` VALUES ('1462', '2020-06-21 05:22:03', '3018122', null);
INSERT INTO `xminutesset` VALUES ('1473', '2020-06-21 05:18:59', '3018122', null);
INSERT INTO `xminutesset` VALUES ('1481', '2020-06-21 05:18:03', '3018122', null);