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
Aggiornamento per più tabelle
Da una vista di normalizzazione della struttura del database, è meglio usare una tabella e avere un archivio che identifichi quale colonna è quale robot, se ciò non è possibile per qualche motivo, puoi ottenerlo unendo le tabelle:
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