Answer the question
In order to leave comments, you need to log in
how to use while in mysql?
Hello!
It is necessary to add results through while, but something does not work. Here is the code:
BEGIN
DECLARE population int;
DECLARE total2 int DEFAULT 0 ;
DECLARE irows int ;
SET irows = (SELECT COUNT(d.Population) FROM MDepartments d LEFT JOIN Localities l ON d.LocalityId = l.Id WHERE d.ParentId = Parent AND Type = 0);
IF irows>=1 THEN
SELECT d.Population FROM MDepartments d LEFT JOIN Localities l ON d.LocalityId = l.Id WHERE d.ParentId = Parent AND Type = 0 INTO population;
WHILE irows >= 0 DO
SET total = total+population;
END WHILE;
ELSE
SET total = 250;
END IF;
END
SELECT d.Population FROM MDepartments d LEFT JOIN Localities l ON d.LocalityId = l.Id WHERE d.ParentId = Parent AND Type = 0 INTO population;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question