通过组合字符串将不同的行归为一组 [英] Group different rows in one by combining strings

查看:17
本文介绍了通过组合字符串将不同的行归为一组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的数据集:

I have a data set like this:

Column1  Column2
   1       A
   1       B
   1       C
   2       D
   2       E
   2       F
   2       G
   3       H
   3       I 

我想把它合并成这样的:

and I would like to merge it into something like this:

Column1  Column2
   1       A, B, C
   2       D, E, F, G
   3       H, I

是否可以在 SQLite 中以某种方式执行此操作?我虽然是 GROUP BY Column1,但我不知道如何将 Column2 数据合并到一个字符串中...

Is it possible to do this in SQLite somehow? I though of GROUP BY Column1, but I don't see how I can combine the Column2 data in one string...

谢谢!

推荐答案

 SELECT Column1, group_concat(Column2) FROM Table GROUP BY Column1

group_concat 需要一个可选的第二个参数(一个字符串)作为连接分隔符,如果你不想要单个 ',' 字符.

group_concat takes an optional second argument (a string) to use as the concatenation separator if you don't want a single ',' character.

这篇关于通过组合字符串将不同的行归为一组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆