gpt4 book ai didi

php - 从表中获取多个值

转载 作者:行者123 更新时间:2023-11-30 01:17:05 24 4
gpt4 key购买 nike

我有一 table 顾客

| id | firstname | | 1  | paul      || 2  | steve     || 3  | chris     |

第二个表名为 list_customer

| id | id_customer | id_list || 1  |     1       |    1    || 2  |     1       |    2    || 3  |     2       |    1    |

每个客户可以位于 x 个列表中

第三个表称为列表

| id_list | color ||    1    | #fff  ||    2    | #000  ||    3    | #ccc  |

通过 mysql 查询,我想获取名字和列表颜色。客户可以位于多个列表中。

最佳答案

select c.firstname, group_concat(l.color) as colors
from customers c
inner join list_customer lc on lc.id_customer = c.id
inner join list l on l.id_list = lc.id_list
group by c.firstname

关于php - 从表中获取多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18947048/

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