Código SQL:
Ver original
DELIMITER $ CREATE PROCEDURE ejercicio1 () BEGIN DECLARE SUM INT; DECLARE cla CHAR; DECLARE punt INT; DECLARE var1 INT DEFAULT 2; SELECT SUM(tantos_marcados) AS tantos, clase FROM jugadores GROUP BY clase ORDER BY tantos DESC; DECLARE cursor1 CURSOR FOR SELECT SUM(tantos_marcados) AS tantos, j.clase, c.puntuacion FROM jugadores AS j INNER JOIN clases AS c ON j.clase = c.codigo GROUP BY j.clase ORDER BY tantos DESC LIMIT 2; /* DECLARE CONTINUE HANDLER FOR NOT FOUND SET @var1 = 0; */ OPEN cursor1; IF var1 = 2 THEN SET var1 = 1; FETCH cursor1 INTO SUM, cla, punt; SET punt = punt + 2; UPDATE clases SET puntuacion = punt WHERE codigo = cla; ELSE IF var1 = 1 THEN SET var1 = 0; FETCH cursor1 INTO SUM, cla, punt; SET punt = punt + 1; UPDATE clases SET puntuacion = punt WHERE codigo = cla; END IF; CLOSE cursor1; END$ DELIMITER ;