group-concat

Use LINQ to concatenate multiple rows into single row (CSV property)

强颜欢笑 提交于 2019-11-26 20:43:53
I'm looking for the LINQ equivalent to the Sybase's LIST() or MySQL's group_concat() It'll convert: User Hobby -------------- Bob Football Bob Golf Bob Tennis Sue Sleeping Sue Drinking To: User Hobby -------------- Bob Football, Golf, Tennis Sue Sleeping, Drinking That's the GroupBy operator. Are you using LINQ to Objects? Here's an example: using System; using System.Collections.Generic; using System.Linq; public class Test { static void Main() { var users = new[] { new { User="Bob", Hobby="Football" }, new { User="Bob", Hobby="Golf" }, new { User="Bob", Hobby="Tennis" }, new { User="Sue",

Concatenate and group multiple rows in Oracle [duplicate]

点点圈 提交于 2019-11-26 20:35:23
Possible Duplicate: how to retrieve two columns data in A,B format in Oracle Suppose I have a table like this: NAME GROUP_NAME name1 groupA name2 groupB name5 groupC name4 groupA name3 groupC I'd like to have a result like this: GROUP_NAME NAMES groupA name1,name4 groupB name2 groupC name3,name5 If there were only one column in the table, I could concatenate the records by doing the following, but with grouping in the context, I really don't have much idea. Concatatenating one column table: SELECT names FROM (SELECT SYS_CONNECT_BY_PATH(names,' ') names, level FROM name_table START WITH names =

using group_concat in PHPMYADMIN will show the result as [BLOB - 3B]

风格不统一 提交于 2019-11-26 19:17:44
问题 I have a query which uses the GROUP_CONCAT of mysql on an integer field. I am using PHPMYADMIN to develop this query. My problem that instead of showing 1,2 which is the result of the concatenated field, I get [BLOB - 3B]. Query is SELECT rec_id,GROUP_CONCAT(user_id) FROM t1 GROUP BY rec_id (both fields are unsigned int, both are not unique) What should I add to see the actual results? 回答1: Looks as though GROUP_CONCAT expects that value to be a string. I just ran into the same problem.

MySQL: GROUP_CONCAT with LEFT JOIN

主宰稳场 提交于 2019-11-26 19:08:00
问题 I'm experiencing a problem with MySQL's "GROUP_CONCAT" function. I will illustrate my problem using a simple help desk database: CREATE TABLE Tickets ( id INTEGER NOT NULL PRIMARY KEY, requester_name VARCHAR(255) NOT NULL, description TEXT NOT NULL); CREATE TABLE Solutions ( id INTEGER NOT NULL PRIMARY KEY, ticket_id INTEGER NOT NULL, technician_name VARCHAR(255) NOT NULL, solution TEXT NOT NULL, FOREIGN KEY (ticket_id) REFERENCES Tickets.id); INSERT INTO Tickets VALUES(1, 'John Doe', 'My

is there a length limit to group_concat or another reason why it would not work on a text field

扶醉桌前 提交于 2019-11-26 16:54:02
问题 First, here is the query: SELECT GROUP_CONCAT(title) title, GROUP_CONCAT(description) description, skill_id, count(*) FROM jobs j INNER JOIN job_feed_details d ON j.id = d.job_id JOIN jobs_skills js ON j.id = js.job_id WHERE moderated = 1 group by skill_id Everything works as expected except the description field only returns one result, instead of a concatenation of all results. I suspect this is because the description is a text field, but I cannot find anything about why concatenation

GROUP_CONCAT equivalent in Django

∥☆過路亽.° 提交于 2019-11-26 16:43:38
问题 Say I have the following table called fruits : id | type | name ----------------- 0 | apple | fuji 1 | apple | mac 2 | orange | navel My goal is to ultimately come up with a count of the different types and a comma-delimited list of the names : apple, 2, "fuji,mac" orange, 1, "navel" This can be easily done with GROUP_CONCAT in MySQL but I'm having trouble with the Django equivalent. This is what I have so far but I am missing the GROUP_CONCAT stuff: query_set = Fruits.objects.values('type')

Show a one to many relationship as 2 columns - 1 unique row (ID & comma separated list)

风流意气都作罢 提交于 2019-11-26 15:28:10
I need something similar to these 2 SO questions, but using Informix SQL syntax. Concatenate several fields into one with SQL SQL Help: Select statement Concatenate a One to Many relationship My data coming in looks like this: id codes 63592 PELL 58640 SUBL 58640 USBL 73571 PELL 73571 USBL 73571 SUBL I want to see it come back like this: id codes 63592 PELL 58640 SUBL, USBL 73571 PELL, USBL, SUBL See also group_concat() in Informix . I believe that the answer you need is a user-defined aggregate, similar to this one: CREATE FUNCTION gc_init(dummy VARCHAR(255)) RETURNING LVARCHAR; RETURN '';

GROUP_CONCAT in SQLite

纵然是瞬间 提交于 2019-11-26 14:35:34
问题 I am having data like this 1 A 1 B 1 C 1 D 2 E 2 F 3 G 3 H 3 I 3 J 3 K by using this query select ABSTRACTS_ITEM._id,Name from ABSTRACTS_ITEM , ABSTRACT_AUTHOR , AUTHORS_ABSTRACT where ABSTRACTS_ITEM._id = AUTHORS_ABSTRACT.ABSTRACTSITEM_ID and ABSTRACT_AUTHOR._id = AUTHORS_ABSTRACT.ABSTRACTAUTHOR_ID Now, I want to show data like this 1 A,B,C,D 2 EF and so on..I also know it can achieve by GROUP_CONCAT function. So, I tried with this SELECT ABSTRACTS_ITEM._id, GROUP_CONCAT(ABSTRACT_AUTHOR.NAME

MySQL DISTINCT on a GROUP_CONCAT()

若如初见. 提交于 2019-11-26 11:43:10
I am doing SELECT GROUP_CONCAT(categories SEPARATOR ' ') FROM table . Sample data below: categories ---------- test1 test2 test3 test4 test1 test3 test1 test3 However, I am getting test1 test2 test3 test4 test1 test3 back and I would like to get test1 test2 test3 test4 back. Any ideas? Many thanks! Naktibalda GROUP_CONCAT has DISTINCT attribute: SELECT GROUP_CONCAT(DISTINCT categories ORDER BY categories ASC SEPARATOR ' ') FROM table Using DISTINCT will work SELECT GROUP_CONCAT(DISTINCT(categories) SEPARATOR ' ') FROM table REf:- this Other answers to this question do not return what the OP

How create json format with group-concat mysql?

强颜欢笑 提交于 2019-11-26 09:25:47
问题 How create json format with group-concat mysql? (I use MySQL) Example1: table1: email | name | phone ------------------------------------- my1@gmail.com | Ben | 6555333 my2@gmail.com | Tom | 2322452 my2@gmail.com | Dan | 8768768 my1@gmail.com | Joi | 3434356 like syntax code that not give me the format: select email, group-concat(name,phone) as list from table1 group by email output that I need: email | list ------------------------------------------------ my1@gmail.com | {name:\"Ben\",phone: