SET @last_task = 0;
SELECT SUM(new_task) AS tasks_performed
FROM (
SELECT
IF(@last_task = RobotShortestPath, 0, 1) AS new_task,
@last_task := RobotShortestPath
FROM table
ORDER BY ??
) AS tmp
Актуализация за множество таблици
От изглед за нормализиране на структурата на базата данни е по-добре с една таблица и да имате поле, идентифициращо коя колона какъв робот е, ако това не е възможно по някаква причина, можете да получите това чрез обединяване на таблиците:
SET @last_task = 0;
SELECT robot_id, SUM(new_task) AS tasks_performed
FROM (
SELECT
IF(@last_task = RobotShortestPath, 0, 1) AS new_task,
@last_task := RobotShortestPath
FROM (
SELECT 1 AS robot_id, robot_log_1.* FROM robot_log_1
UNION SELECT 2, robot_log_2.* FROM robot_log_2
UNION SELECT 3, robot_log_3.* FROM robot_log_3
UNION SELECT 4, robot_log_4.* FROM robot_log_4
UNION SELECT 5, robot_log_5.* FROM robot_log_5
) as robot_log
ORDER BY robot_id, robot_log_id
) AS robot_log_history
GROUP BY robot_id
ORDER BY tasks_performed DESC