如果有一种方法可以使用 group_concat 实现下面的这种结果

If there is a way to achieve this kind of result below using group_concat

数据

Brcode  name
1.      A
2.      A
3.      A

预期结果

Brcode  Name Common
1        A             1,2,3
2        A              1,2,3
3        A              1,2,3
 

是的,你可以加入。

CREATE TABLE test_tbl        (
             Brcode int(9),
              name varchar(3) );


    INSERT INTO test_tbl VALUES (1,'A'),
                                (2,'A'),
                                (3,'A');
    

SELECT t1.Brcode,
       t1.name,
       t2.common
FROM test_tbl t1       
inner join 
(
  select name ,group_concat(Brcode  SEPARATOR ',') as Common from test_tbl group by name
) as t2 on t1.name=t2.name;

演示:https://www.db-fiddle.com/f/7yUJcuMJPncBBnrExKbzYz/99

结果: