0

我有下表名为“功能”:

id  feature
-----------------------
1   aa
2   bb
3   cc
4   dd
5   ee
6   ff

有没有办法根据分隔字符串查询此表?就像是:

select * from features where {some magic here} = "1,4,5"

哪个应该只返回相应的记录?

4

4 回答 4

2

IN关键字,它可以使用一组值而不是您尝试过的任何值。对于此示例,它将类似于

SELECT * FROM features WHERE id IN (1,4,5)
于 2014-06-17T15:11:08.777 回答
1

使用 IN:-

select * 
from features where id IN (1,4,5)

或者你的意思是一个传递的字符串?

于 2014-06-17T15:12:14.270 回答
1

像这样使用 IN 子句:

select * from features where id IN(1,4,5);

或者

select * from features where feature IN ('aa','dd','ee');
于 2014-06-17T15:12:48.940 回答
1

不是 100% 确定我知道你在问什么 - 你是在尝试提取与一组 ID 匹配的所有记录还是在寻找包含特定字符串的功能?

对于前者:

select * from features where id in (1,4,5);

对于后者:

select * from features where feature like '%1,4,5%';
于 2014-06-17T15:14:39.620 回答