I currently have some sql that brings back tags. they should have distinct ids, but they don't.... so my current data is like:
我目前有一些带回标签的sql。他们应该有不同的ID,但他们不....所以我目前的数据是这样的:
Microsoft | GGG | 1 | 167
Microsoft | GGG | 1 | 2
Microsoft | GGG | 1 | 1
What i would like to do is have only one row come back with the final column concatenated into a delimited list like:
我想做的是只返回一行,最后一列连接成一个分隔列表,如:
Microsoft | GGG | 1 | 167, 2, 1
I am using mySQL 5 for this.
我正在使用mySQL 5。
1 个解决方案
#1
22
Use GROUP_CONCAT()
for this, with a GROUP BY
covering the other three columns:
使用GROUP_CONCAT(),GROUP BY覆盖其他三列:
SELECT
name, -- Microsoft
other, -- GGG
other2, -- 1
GROUP_CONCAT(id) AS ids
FROM tbl
GROUP BY name, other, other2
#1
22
Use GROUP_CONCAT()
for this, with a GROUP BY
covering the other three columns:
使用GROUP_CONCAT(),GROUP BY覆盖其他三列:
SELECT
name, -- Microsoft
other, -- GGG
other2, -- 1
GROUP_CONCAT(id) AS ids
FROM tbl
GROUP BY name, other, other2