【问题标题】:How to select records of same id and group it to one record?如何选择相同id的记录并将其分组为一条记录?
【发布时间】:2016-06-10 11:29:55
【问题描述】:

我有一个表,列有“ID”、“Plans”、“Type”、“Type_id”

ID | Type    | Plans       | Type_id
_____________________________________
1  | Package | Gold        | 3
1  | Package | Silver      | 2
1  | Package | Platinum    | 4
1  | Channel | HollywoodOn | 200

我想要这样的输出:

ID | Type    | Plans       
_____________________________________
1  | Package | Gold,Silver,Platinum      
1  | Channel | HollywoodOn 

请帮助伙计们。谢​​谢。 P.S:对不起,我以前发布的愚蠢格式。我是堆栈溢出的菜鸟。

【问题讨论】:

  • 考虑使用group_concatgroup by
  • 感谢 Reddy 成功了

标签: mysql database select jdbc records


【解决方案1】:

SELECT id,TYPE,GROUP_CONCAT(plans SEPARATOR ', ') AS Plans FROM plans GROUP BY TYPE

【讨论】:

    猜你喜欢
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-14
    • 1970-01-01
    • 2017-02-24
    • 2021-12-26
    相关资源
    最近更新 更多