Det er ogs[ en lidt obskur løsning.
Manalen er:
https://dev.mysql.com/doc/refman/8.0/en/set.htmlhvor +0 tricket beskrives.
Så skal man naturligvis forstå binær AND.
Her er en demo:
mysql> CREATE TABLE u (
-> name VARCHAR(32),
-> grps SET ('A','B','C','D'),
-> PRIMARY KEY(name)
-> );
Query OK, 0 rows affected (0.03 sec)
mysql> INSERT INTO u VALUES('Anders', 'A,B');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO u VALUES('Børge', 'B,C');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO u VALUES('Christian', 'D');
Query OK, 1 row affected (0.01 sec)
mysql> SELECT name,grps FROM u;
+-----------+------+
| name | grps |
+-----------+------+
| Anders | A,B |
| Børge | B,C |
| Christian | D |
+-----------+------+
3 rows in set (0.00 sec)
mysql> SELECT name,(grps+0) FROM u;
+-----------+----------+
| name | (grps+0) |
+-----------+----------+
| Anders | 3 |
| Børge | 6 |
| Christian | 8 |
+-----------+----------+
3 rows in set (0.00 sec)
mysql> SELECT u1.name,u1.grps,(u1.grps+0),u2.name,u2.grps,(u2.grps+0),((u1.grps+0) & (u2.grps+0))
-> FROM u u1 JOIN u u2 ON u1.name <> u2.name;
+-----------+------+-------------+-----------+------+-------------+-----------------------------+
| name | grps | (u1.grps+0) | name | grps | (u2.grps+0) | ((u1.grps+0) & (u2.grps+0)) |
+-----------+------+-------------+-----------+------+-------------+-----------------------------+
| Christian | D | 8 | Anders | A,B | 3 | 0 |
| Børge | B,C | 6 | Anders | A,B | 3 | 2 |
| Christian | D | 8 | Børge | B,C | 6 | 0 |
| Anders | A,B | 3 | Børge | B,C | 6 | 2 |
| Børge | B,C | 6 | Christian | D | 8 | 0 |
| Anders | A,B | 3 | Christian | D | 8 | 0 |
+-----------+------+-------------+-----------+------+-------------+-----------------------------+
6 rows in set (0.00 sec)
mysql> DROP TABLE u;
Query OK, 0 rows affected (0.01 sec)