如何在IN查询中使用以下变量内容...
SET @var = '1,2,3';
SELECT * FROM Table WHERE ID IN (@var);
答案 0 :(得分:1)
使用JOIN
SELECT t1.*
FROM Table t1
JOIN Table t2 on t1.OtherID = t2.OtherID
WHERE t2.X = 1
答案 1 :(得分:0)
通过查看this answer
找到解决方案SET @var = '1,2,3';
SET @Expression=CONCAT('SELECT * FROM TableWHERE ID IN (',@var,')');
PREPARE myquery FROM @Expression;
EXECUTE myquery