gpt4 book ai didi

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

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

Possible Duplicate:
mysql with comma separated values

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

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,然后在下一个查询中将其排除。该查询是“SELECT number_id, number_name FROM Numberstable ORDER BY 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 |
-----------------------

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

关于PHP&MySQL : Combine more lines and put it in array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11972569/

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