string-aggregation

How can multiple rows be concatenated into one in Oracle without creating a stored procedure? [duplicate]

喜夏-厌秋 提交于 2019-11-26 03:56:14
问题 This question already has an answer here: SQL Query to concatenate column values from multiple rows in Oracle 11 answers How can I achieve the following in oracle without creating a stored procedure? Data Set: question_id element_id 1 7 1 8 2 9 3 10 3 11 3 12 Desired Result: question_id element_id 1 7,8 2 9 3 10,11,12 回答1: There are many way to do the string aggregation, but the easiest is a user defined function. Try this for a way that does not require a function. As a note, there is no

Simulating group_concat MySQL function in Microsoft SQL Server 2005?

霸气de小男生 提交于 2019-11-26 01:17:11
问题 I\'m trying to migrate a MySQL-based app over to Microsoft SQL Server 2005 (not by choice, but that\'s life). In the original app, we used almost entirely ANSI-SQL compliant statements, with one significant exception -- we used MySQL\'s group_concat function fairly frequently. group_concat , by the way, does this: given a table of, say, employee names and projects... SELECT empName, projID FROM project_members; returns: ANDY | A100 ANDY | B391 ANDY | X010 TOM | A100 TOM | A510 ... and here\'s

How do I create a comma-separated list using a SQL query?

前提是你 提交于 2019-11-25 23:47:22
问题 I have 3 tables called: Applications (id, name) Resources (id, name) ApplicationsResources (id, app_id, resource_id) I want to show on a GUI a table of all resource names. In one cell in each row I would like to list out all of the applications (comma separated) of that resource. So the question is, what is the best way to do this in SQL as I need to get all resources and I also need to get all applications for each resource? Do I run a select * from resources first and then loop through each

How can I combine multiple rows into a comma-delimited list in Oracle? [duplicate]

混江龙づ霸主 提交于 2019-11-25 23:08:59
问题 This question already has an answer here: SQL Query to concatenate column values from multiple rows in Oracle 11 answers I have a simple query: select * from countries with the following results: country_name ------------ Albania Andorra Antigua ..... I would like to return the results in one row, so like this: Albania, Andorra, Antigua, ... Of course, I can write a PL/SQL function to do the job (I already did in Oracle 10g), but is there a nicer, preferably non-Oracle-specific solution (or

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

How to concatenate strings of a string field in a PostgreSQL 'group by' query?

风格不统一 提交于 2019-11-25 22:07:18
问题 I am looking for a way to concatenate the strings of a field within a group by query. So for example, I have a table: ID COMPANY_ID EMPLOYEE 1 1 Anna 2 1 Bill 3 2 Carol 4 2 Dave and I wanted to group by company_id to get something like: COMPANY_ID EMPLOYEE 1 Anna, Bill 2 Carol, Dave There is a built-in function in mySQL to do this group_concat 回答1: PostgreSQL 9.0 or later: Recent versions of Postgres (since late 2010) have the string_agg(expression, delimiter) function which will do exactly

SQL Query to concatenate column values from multiple rows in Oracle

天大地大妈咪最大 提交于 2019-11-25 21:44:39
问题 Would it be possible to construct SQL to concatenate column values from multiple rows? The following is an example: Table A PID A B C Table B PID SEQ Desc A 1 Have A 2 a nice A 3 day. B 1 Nice Work. C 1 Yes C 2 we can C 3 do C 4 this work! Output of the SQL should be - PID Desc A Have a nice day. B Nice Work. C Yes we can do this work! So basically the Desc column for out put table is a concatenation of the SEQ values from Table B? Any help with the SQL? 回答1: There are a few ways depending on

How to make a query with group_concat in sql server [duplicate]

為{幸葍}努か 提交于 2019-11-25 21:42:02
问题 This question already has answers here : Simulating group_concat MySQL function in Microsoft SQL Server 2005? (10 answers) Closed 3 years ago . I know that in sql server we cannot use Group_concat function but here is one issue i have in which i need to Group_Concat my query.I google it found some logic but not able to correct it.My sql query is select m.maskid,m.maskname,m.schoolid,s.schoolname, md.maskdetail from tblmask m join school s on s.id = m.schoolid join maskdetails md on m.maskid =