SQL IN子句只提供开始和结束数字

时间:2013-01-10 15:26:21

标签: mysql sql

有没有办法为IN的子句提供一个未定义的集合?

如:

select * from ABC WHERE MY_ID IN (X TO Y)

示例:如果我将X赋予3,将Y赋予8;

select * from ABC WHERE MY_ID IN (3, ... , 8)

这应该与:

相同
select * from ABC WHERE MY_ID IN (3, 4, 5, 6, 7, 8)

3 个答案:

答案 0 :(得分:6)

你需要这个

select * from ABC WHERE MY_ID between 3 and 8

答案 1 :(得分:2)

也可以试试这个......

select * from abc where id >= 3 and id <=8

答案 2 :(得分:1)

BETWEEN

怎么样?
SELECT * FROM ABC WHERE MY_ID BETWEEN 3 AND 8