I have a MySQL table with the following definition:
+--------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+---------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| numbers| json | YES | | NULL | |
+--------+---------+------+-----+---------+-------+
The table has some sample data as follows:
+----+------+----------------------------------+
| id | numbers |
+----+------+----------------------------------+
| 1 | [1,2,3,4,5] |
| 2 | [2,3,7,8,9] |
| 3 | [5,7,10,15] |
+----+------+----------------------------------+
How can I calculate the total number of matched numbers (2,3,7,10) for each card? For example:
+----+---------+
| ID | Matches |
+----+---------+
| 1 | 2 |
| 2 | 3 |
| 3 | 2 |
+----+---------+
numbersis equal[2,2]then you need the result of1or2? Do not tell "the array cannot have duplicated values" - or prove this by table's CREATE TABLE with according CHECK constraint.