group-concat

Concatenate column values for rows with the same values (of different columns)

喜夏-厌秋 提交于 2019-11-28 02:05:20
SQL Server 2005 I have a table which returns ID name prop value -------------------------- 1 one Prop1 a 1 one Prop1 b 1 one Prop2 c 2 two Prop1 d 2 two Prop2 e How can I run a select on it to return ID name prop value ----------------------------- 1 one Prop1 a,b 1 one Prop2 c 2 two Prop1 d 2 two Prop2 e try this: --Concatenation with FOR XML and eleminating control/encoded character expansion "& < >" set nocount on; declare @YourTable table (RowID int, RowName varchar(5), prop varchar(5), RowValue varchar(5)) insert into @YourTable VALUES (1,'one','Prop1','a') insert into @YourTable VALUES

MySQL - How to display row value as column name using concat and group_concat

好久不见. 提交于 2019-11-28 01:39:42
Table 1: id | typeid | available| 0 | 1 | 12 | 0 | 2 | 44 | Table 2: typeid | typename | 1 | CL | 2 | ML | I have a query using concat and group_concat : select id,concat(group_concat(typename,available)) as types from table1 join table2 on table2.typeid=table1.typeid I got the result as: id | types | 0 | CL12,ML44 | But I want to display it like this: id | CL | ML | 0 | 12 | 44 | Is there any way to split the group_concat result to columns heads ? I want dynamically fetch data from table2. Some user can add data to table2. So hard-coding typename is not possible. You should use table pivoting

JPA Criteria API group_concat usage

戏子无情 提交于 2019-11-28 01:35:28
I am currently working on a report which needs a group_concat for one of the fields. CriteriaQuery<GameDetailsDto> criteriaQuery = criteriaBuilder .createQuery(GameDetailsDto.class); Root<BetDetails> betDetails = criteriaQuery.from(BetDetails.class); Expression<String> betSelection = betDetails.get("winningOutcome"); criteriaQuery.multiselect( // other fields to select criteriaBuilder.function("group_concat", String.class, betSelection), // other fields to select ); //predicate, where clause and other filters TypedQuery<GameDetailsDto> typedQuery = entityManager.createQuery(criteriaQuery);

Combining rows of queried results by unique identifier?

寵の児 提交于 2019-11-28 01:28:08
I have a query that searches through several tables and returns one row for every value in one specific column of one of the queried tables. The table returns multiple rows for one unique identifier. What I want to do is combine those rows that have the same unique identifier and combine 2 of the column's value separated by commas and return those values as a unique column. Example: Museum MuseumID Country City Paintings Sculptures Louvre 345 France Paris Mona Lisa NULL Louvre 345 France Paris NULL Venus De Milo Louvre 345 France Paris Ship of Fools NULL Instead I would like to make the query

What is the maximum allowance for group_concat_max_len in MySQL?

落花浮王杯 提交于 2019-11-27 22:11:58
问题 I am using a group_concat to concatenate a lot of rows into one. I set group concat to 10000 using: SET group_concat_max_len = 10000; But even then, my output cells remain incomplete and end with ... I tried setting group_concat_max_len = 20000 and even that didn't help. I also tried setting group_concat_max_len to 99999999. It still doesn't complete my output text. And I checked one of the group concat stops at Length = 230 characters and then gives ... Is there any other way? 回答1: Check out

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

自古美人都是妖i 提交于 2019-11-27 18:05: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? Looks as though GROUP_CONCAT expects that value to be a string. I just ran into the same problem. Solved it by converting the int column to a string like so: SELECT rec_id,GROUP_CONCAT(CONVERT(user_id, CHAR(8)))

MySQL: GROUP_CONCAT with LEFT JOIN

天大地大妈咪最大 提交于 2019-11-27 17:41:29
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 computer is not booting.'); INSERT INTO Tickets VALUES(2, 'Jane Doe', 'My browser keeps crashing.');

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

本小妞迷上赌 提交于 2019-11-27 14:44:17
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 would not work with a text field. Anyone know why this would not work? The group_concat result length is

GROUP_CONCAT equivalent in Django

天涯浪子 提交于 2019-11-27 14:41:41
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').annotate(count=Count('type')).order_by('-count') I would like to avoid using raw SQL queries if

JOIN and GROUP_CONCAT with three tables

陌路散爱 提交于 2019-11-27 14:01:40
问题 I have three tables: users: sports: user_sports: id | name id | name id_user | id_sport | pref ---+-------- ---+------------ --------+----------+------ 1 | Peter 1 | Tennis 1 | 1 | 0 2 | Alice 2 | Football 1 | 2 | 1 3 | Bob 3 | Basketball 2 | 3 | 0 3 | 1 | 2 3 | 3 | 1 3 | 2 | 0 The table user_sports links users and sports with an order of preference ( pref ). I need to make a query that returns this: id | name | sport_ids | sport_names ---+-------+-----------+---------------------------- 1 |