BEGIN
CREATE TEMPORARY TABLE temp_users LIKE users;
SET @fact_id = FactId;
SELECT count(*) INTO @CheckExists from users WHERE fact_id = @fact_id;
WHILE(@CheckExists > 0)
DO
INSERT temp_users SELECT * FROM users WHERE fact_id = @fact_id;
SELECT fact_id into @fact_id FROM users WHERE fact_id = @fact_id;
SELECT count(*) INTO @CheckExists from users WHERE fact_id = @fact_id;
END WHILE;
SELECT * FROM temp_users;
END
我不明白为什么当我在循环之外创建SELECT * FROM temp_users;
时我得到一个空表,但如果我在while循环中进行此查询,我可以得到一些行