我正在使用API来返回场地列表。
SELECT
`sample`.Fascia AS 'Fascia',
`sample`.Category AS 'Category'
FROM
`sample`
WHERE
`sample`.`PostCode` LIKE '%SW1%'
然后返回一个场地列表。
Fascia | Category
------------+-------------
Sainsbury's | Supermarkets
Waitrose | Supermarkets
99p Store | Hardware
T K Max | Clothing
如何修改查询以将类别组合在一起并创建一个抽象列,将这些场所列为逗号列表。像这样的东西
Category | Grouped Venues
--------------+------------------------
Supermarkets | Sainsbury's, Waitrose
Hardware | 99p Store
Clothing | T K Max
答案 0 :(得分:1)
使用Group_concat:
SELECT
Group_concat(`sample`.Fascia) AS 'Grouped Venues',
`sample`.Category AS 'Category'
FROM
`sample`
WHERE `sample`.`PostCode` LIKE '%SW1%'
Group by `sample`.Category