【问题标题】:concat values group by mysql [duplicate]mysql的concat值组[重复]
【发布时间】:2020-08-28 21:02:33
【问题描述】:

如何从中获得:

id foo_name 1个 2个 3个 4个 5乙 6乙 7乙 8个 9乙 10安

对此: 仅 1 行

foo_names 甲,乙

我尝试使用GROUP_CONCAT,但它给了我这个:

A,A,A,A,A,A,A,

B,B,B,B

【问题讨论】:

    标签: mysql sql


    【解决方案1】:

    group_concat():

    select group_concat(distinct foo_name order by foo_name) foo_names
    from tablename
    

    请参阅demo

    【讨论】:

      【解决方案2】:

      你可以使用:

      select group_concat(distinct foo_name) as foo_names
      from t;
      

      【讨论】:

      • 对不起,我不够清楚,但我已经编辑了问题,它应该只返回一行
      • @woninana 。 . .你跑过这个吗?它返回一行,名称中只有两个值。这就是你要求的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-02
      • 1970-01-01
      相关资源
      最近更新 更多