group-concat

Postgresql GROUP_CONCAT equivalent?

青春壹個敷衍的年華 提交于 2019-11-25 22:36:38
问题 I have a table and I\'d like to pull one row per id with field values concatenated. In my table, for example, I have this: TM67 | 4 | 32556 TM67 | 9 | 98200 TM67 | 72 | 22300 TM99 | 2 | 23009 TM99 | 3 | 11200 And I\'d like to output: TM67 | 4,9,72 | 32556,98200,22300 TM99 | 2,3 | 23009,11200 In MySQL I was able to use the aggregate function GROUP_CONCAT , but that doesn\'t seem to work here... Is there an equivalent for PostgreSQL, or another way to accomplish this? 回答1: This is probably a

Can I concatenate multiple MySQL rows into one field?

余生颓废 提交于 2019-11-25 21:37:50
问题 Using MySQL , I can do something like: SELECT hobbies FROM peoples_hobbies WHERE person_id = 5; My Output: shopping fishing coding but instead I just want 1 row, 1 col: Expected Output: shopping, fishing, coding The reason is that I\'m selecting multiple values from multiple tables, and after all the joins I\'ve got a lot more rows than I\'d like. I\'ve looked for a function on MySQL Doc and it doesn\'t look like the CONCAT or CONCAT_WS functions accept result sets, so does anyone here know

How to concatenate text from multiple rows into a single text string in SQL server?

假装没事ソ 提交于 2019-11-25 21:33:09
问题 Consider a database table holding names, with three rows: Peter Paul Mary Is there an easy way to turn this into a single string of Peter, Paul, Mary ? 回答1: If you are on SQL Server 2017 or Azure, see Mathieu Renda answer. I had a similar issue when I was trying to join two tables with one-to-many relationships. In SQL 2005 I found that XML PATH method can handle the concatenation of the rows very easily. If there is a table called STUDENTS SubjectID StudentName ---------- ------------- 1