PHP&MySQL:组合更多行并将其放在数组中


PHP&MySQL: Combine more lines and put it in array

可能的重复项:
带有逗号分隔值的 MySQL

我有两个表,行更多,如下所示:

1. numberstable
    ---------------------------
    | number_id | number_name |
    ---------------------------
    |    1      |     one     |
    |    2      |     two     |
    |    3      |     three   |
    |    4      |     four    |
                .
                .
                .
    ---------------------------
2. testtable
    -------------------------------
    | test_id | numbers | sthelse |
    -------------------------------
    |    1    | 2.4.5.6 | text1   |
    |    2    | 4.8.7.1 | text2   |
    |    3    | 2.7.8.5 | text3   |
    -------------------------------

首先,我想组合表"testtable"中的所有三个"数字"行以获得如下所示的内容:1.2.4.5.6.7.8,然后在下一个查询中排除它。此查询是"选择number_id,number_name从数字稳定顺序按number_name"。排除后,我想只显示"testtable"中未使用的数字(9、10、11 等)。

怎么做?

如果您尝试将数字稳定与可测试对象相关联。我认为您最好添加另一个表,该表将两者与您拥有类似架构的位置联系起来

1. numberstable
    ---------------------------
    | number_id | number_name |
    ---------------------------
    |    1      |     one     |
    |    2      |     two     |
    |    3      |     three   |
    |    4      |     four    |
                .
                .
                .
    ---------------------------
2. testtable
    ---------------------
    | test_id | sthelse |
    ---------------------
    |    1    | text1   |
    |    2    | text2   |
    |    3    | text3   |
    --------------------
3. numbersintesttable
    -----------------------
    | test_id | number_id |
    -----------------------
    |    1    | 2         |
    |    1    | 4         |
    |    1    | 5         |
    |    1    | 6         |
    |    2    | 4         |
    |    2    | 8         |
    |    2    | 7         |
    |    2    | 1         |
    -----------------------

因此,新表将是一个多对多联接表,您可以使用它通过利用所需的联接类型(内部、外部等)在单个查询中获取所有需要的数据。