无法将int列表作为变量传递

时间:2019-04-24 21:36:59

标签: mysql sql dbeaver

我正在使用DBeaber 6.0.3并尝试进行此查询

declare @samplesList table (id int);
insert @samplesList(id) values(1121),(2121),(3121); 

SELECT *
FROM samples
where samplesId in (select id from @samplesList) 

但是我收到一个Sintax错误 我究竟做错了什么?

1 个答案:

答案 0 :(得分:1)

如果使用的是MySQL v8,则可以通过以下方式重现示例:

with samplesList as (
  select 1121 as id union all
  select 2121 union all
  select 3121 
)
SELECT *
FROM samples
where samplesId in (select id from samplesList)

或在任何版本的MySQL中:

create temporary table samplesList (id int);
insert into samplesList(id) values(1121),(2121),(3121);

SELECT *
FROM samples
where samplesId in (select id from samplesList)