【问题标题】:Display each value on new lines instead of same using group_concat使用 group_concat 在新行上显示每个值而不是相同的值
【发布时间】:2021-06-17 06:31:50
【问题描述】:

我有以下查询来显示结果:

SELECT C.Customer_ID
     , group_concat(CP.Company_description separator '\n') as companyName
  FROM tbl_Customer AS C
  JOIN tbl_Company AS CP
    ON (CP.Customer_ID = C.Customer_ID)
 group 
    by Customer_ID

我得到了想要的结果,但是结果显示为这样。

Customer_ID companyName
1 test1, test2, test3
2 test4, test5, test6

我希望结果显示在这样的新行上

Please Click Here to Refer to What I am Looking for

所以为了更清楚,我是 test1,test2,test3 显示在新行上,如:

测试1

测试2

测试3

【问题讨论】:

    标签: mysql line-breaks group-concat


    【解决方案1】:

    只需在组中添加另一列。像这样

    选择 C.Customer_ID、CP.Company_description 作为公司名称

    FROM tbl_Customer AS C

    inner JOIN tbl_Company AS CP

    开启(CP.Customer_ID = C.Customer_ID)

    按 Customer_ID、CP.Company_description 分组

    【讨论】:

    • 请您再澄清一下,以及如何实现
    猜你喜欢
    • 2017-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-30
    • 1970-01-01
    相关资源
    最近更新 更多