我在每个简单的Mysql查询中花了好几个小时(搜索和尝试)。我试图将一个变量从一个select语句传递给next语句。但我被抛出一排空行。
SET @id :='SELECT MAX(sId) from surveys';
SELECT typeId as type from surveys WHERE sId=@id;
PREPARE stmt from @id;
execute stmt;
我尝试执行SELECT MAX(sId) from surveys
,根据需要提供结果。但似乎@id
不接受这些价值观。是否有任何错误或任何其他建议来解决这个问题?
答案 0 :(得分:0)
尝试这个:
SET @s = 'SELECT typeId as type from surveys WHERE sId=?';
PREPARE stmt from @s;
SET @id = (SELECT MAX(sId) from surveys);
EXECUTE stmt USING @id;
DEALLOCATE PREPARE stmt;