sql字符串cat作为聚合函数:cat多条记录在一起
我有一个包含列的表: (project_id, name)
这是一个人员列表,每个人都有其所属的项目。如果一个人在两个项目中,那就是重复的。
我想提取一个包含以下列的表: (project_id, people) 其中 people 是参与该项目的所有人员姓名的字符串 cat。猫必须用逗号分隔,如下所示:
12, john
12, mark
12, dave
14, luke
成为
12, "john, mark, dave"
14, "luke"
I have a table with columns: (project_id, name)
It's a list of people, each one with the project it belongs to. If a person is in two projects, it is duplicated.
I want to extract a table with columns: (project_id, people) where people is a string cat of the names of all person working on that project. The cat must be comma separated, like this:
12, john
12, mark
12, dave
14, luke
becomes
12, "john, mark, dave"
14, "luke"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
则可以通过简单的查询来完成此操作:
如果您坚持在逗号后留有空格,
you can do this with a simple query
if you insist to have space after the comma:
在这种情况下,组 concat 将帮助您
参考此,http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat
Group concat will help you in this case
Refer this , http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat