如果我有预备陈述的输出;如何将其用作查询的来源?
CALL `myProcedure`;
PREPARE stmnt FROM @allSQL;
EXECUTE stmnt;
DEALLOCATE PREPARE stmnt;
所以,我从EXECUTE stmnt;
得到一个输出(让我们称之为tmp
),我想按照以下方式运行查询:
SELECT * FROM (EXECUTE stmnt) AS tmp WHERE this = that;
答案 0 :(得分:2)
您可以准备一个包含查询结果的CREATE TEMPORARY TABLE
语句:
SET @createSQL = CONCAT('CREATE TEMPORARY TABLE tmp AS ', @allSQL);
PREPARE stmt FROM @createSQL;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SELECT * FROM tmp WHERE this = that;