匹配MySQL查询中数组的元素
让我们首先创建一个表table-
mysql> create table DemoTable1523-> (
-> Id int,
-> Value int
-> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1523 values(1,56);mysql> insert into DemoTable1523 values(2,78);
mysql> insert into DemoTable1523 values(1,34);
mysql> insert into DemoTable1523 values(2,45);
mysql> insert into DemoTable1523 values(1,99);
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1523;
这将产生以下输出-
+------+-------+| Id | Value |
+------+-------+
| 1 | 56 |
| 2 | 78 |
| 1 | 34 |
| 2 | 45 |
| 1 | 99 |
+------+-------+
5 rows in set (0.00 sec)
以下是匹配数组元素的查询。在这里,我们选择具有匹配值34、99和56的id-
mysql> select Id from DemoTable1523-> where Value IN ('34','99','56')
-> group by Id
-> having count(*)=3;
这将产生以下输出-
+------+| Id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
以上是 匹配MySQL查询中数组的元素 的全部内容, 来源链接: utcz.com/z/343558.html