如果我有准备好的语句的输出;如何使用它作为查询的来源?
CALL `myProcedure`;
PREPARE stmnt FROM @allSQL;
EXECUTE stmnt;
DEALLOCATE PREPARE stmnt;
因此,我从
EXECUTE stmnt;
得到一个输出(我们称它为tmp
),我想按照以下方式运行查询:SELECT * FROM (EXECUTE stmnt) AS tmp WHERE this = that;
最佳答案
您可以准备一个包含查询结果的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;
关于mysql - 在查询中将准备好的语句的结果用作临时表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41152126/