[英]Concat multiple rows PSQL
id | name | Subject | Lectured_Times | Faculty
3258132 | Chris Smith | SATS1364 | 10 | Science
3258132 | Chris Smith | ECTS4605 | 9 | Engineering
How would I go about creating the following 我将如何创建以下内容
3258132 Chris Smith SATS1364, 10, Science + ECTS4605, 9,Engineering
where the + is just a new line. +只是换行。 Notice how after the '+'(new line) it doesnt concat the id,name
请注意,在“ +”(新行)之后,它如何不连接ID,名称
try 尝试
SELECT distinct concat(id,"name",string_agg(concat(subject, Lectured_Times , Faculty), chr(10)))
from tn
where id = 3258132
group by id;
As mentioned above string_agg is perfect solution for this. 如上所述,string_agg是完美的解决方案。
select
id, name, string_agg(concat(subject, Lectured_Times, Faculty), '\n')
from table
group by id, name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.