我是新手,并且一直困扰于问题,我有一个表,其中有关于餐馆的大量数据,我的餐馆有多个分支机构,所以我想像下面一样显示它们,因为你可以看到我有三个条目在我餐厅C的表中,我想用一个名字显示它们。
Restaurant A:
123 B town
Restaurant B:
123 C town
Restaurant C:
1 A Town
2 B Town
3 C Town
问题:
我已经进行了查询,但是即使有多个针对该餐厅的记录,它也只为每个餐厅显示一个条目。
SELECT * FROM Restaurants
GROUP BY NAME
最佳答案
样本数据
resturant | branch
-----------------------------
Restaurant A | 123 B town
Restaurant B | 123 C town
Restaurant C | 1 A Town
Restaurant C | 2 B Town
Restaurant C | 3 C Town
询问
SELECT
resturant,
GROUP_CONCAT(branch)
FROM Restaurants
GROUP BY NAME
结果
resturant | branch
-----------------------------
Restaurant A | 123 B town
Restaurant B | 123 C town
Restaurant C | 1 A Town,2 B Town,3 C Town
在分支上使用php explode()
关于php - MYSQL GROUP BY RECORD,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21747956/