dimanche 7 juin 2020

MySQL stored procedure: How to compare two numbers and incrementally count the counter with the higher number

How can I compare two values from two different tables, and incrementally count the table which has the higher score?

I'm getting the error "Syntax error: unexpected '@count1' (at text suffix)

DELIMITER //
CREATE PROCEDURE scoreComparison()
Begin
SET @count1 := 0;
SET @count2 := 0;
IF((SELECT sum(score) from group1) > (SELECT sum(score) from group2)) THEN
    (@count1 := @count1 +1);
    ELSE
    @count2 := @count2 + 1;
    END IF;
END//
DELIMITER ; 


Aucun commentaire:

Enregistrer un commentaire