MySQL的列='x,y,z'?
您可以为此使用IN运算符。
语法如下-
SELECT *FROM yourTableName WHERE yourColumnName IN(‘yourValue1’,‘yourValue2’,‘yourValue3’,...........N);
为了理解上述语法,让我们创建一个表。创建表的查询如下-
create table InOperatorDemo -> ( -> ClientId int -> );
使用insert命令在表中插入一些记录。查询如下-
insert into InOperatorDemo values(101); insert into InOperatorDemo values(110); insert into InOperatorDemo values(120); insert into InOperatorDemo values(230); insert into InOperatorDemo values(270); insert into InOperatorDemo values(300);
使用select语句显示表中的所有记录。查询如下-
select *from InOperatorDemo;
以下是输出-
+----------+ | ClientId | +----------+ | 101 | | 110 | | 120 | | 230 | | 270 | | 300 | +----------+ 6 rows in set (0.00 sec)
这是使用IN运算符从列中获取值的查询-
select *from InOperatorDemo where ClientId IN('120','270','300');
以下是输出-
+----------+ | ClientId | +----------+ | 120 | | 270 | | 300 | +----------+ 3 rows in set (0.00 sec)