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
Mise à jour pour plusieurs tables
À partir d'une vue de normalisation de la structure de la base de données, mieux vaut avoir une table et avoir un fichier identifiant quelle colonne est quel robot, si ce n'est pas possible pour une raison quelconque, vous pouvez l'obtenir en unissant les tables :
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