gpt4 book ai didi

mysql - 有没有办法组合两个 "set"类型的 mysql 字段?

转载 作者:行者123 更新时间:2023-11-29 13:13:52 24 4
gpt4 key购买 nike

有没有办法组合两个字段...都是集合类型?

field1 is ('c')
field2 is ('a')

我想选择该字段以使其返回“a,c”

我尝试过concat,但它返回集合中的重复项。所以如果字段 2 是 ('a','c') 它将返回 'a,c,c'

我也尝试过 field1 和 field2,但因为这是一个集合,所以它返回十进制值。

最佳答案

尝试 field1 | field2 而不是 field1 和 field2

mysql> create table test (id serial, foo set('a','b','c') not null, bar set('a','b','c') not null);
Query OK, 0 rows affected (0.10 sec)

mysql> insert into test (foo,bar) values('a,c','c,b'),('b,a','a'),('a,b','b,c');
Query OK, 3 rows affected (0.05 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from test;
+----+-----+-----+
| id | foo | bar |
+----+-----+-----+
| 1 | a,c | b,c |
| 2 | a,b | a |
| 3 | a,b | b,c |
+----+-----+-----+
3 rows in set (0.01 sec)

mysql> update test set foo = foo | bar;
Query OK, 2 rows affected (0.16 sec)
Rows matched: 3 Changed: 2 Warnings: 0

mysql> select * from test;
+----+-------+-----+
| id | foo | bar |
+----+-------+-----+
| 1 | a,b,c | b,c |
| 2 | a,b | a |
| 3 | a,b,c | b,c |
+----+-------+-----+
3 rows in set (0.00 sec)

关于mysql - 有没有办法组合两个 "set"类型的 mysql 字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21738266/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com