group-concat

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

痞子三分冷 提交于 2019-11-26 07:41:59
问题 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 回答1: 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"

MySQL: Sort GROUP_CONCAT values

别等时光非礼了梦想. 提交于 2019-11-26 07:00:28
问题 In short: Is there any way to sort the values in a GROUP_CONCAT statement? Query: GROUP_CONCAT((SELECT GROUP_CONCAT(parent.name SEPARATOR \" » \") FROM test_competence AS node, test_competence AS parent WHERE node.lft BETWEEN parent.lft AND parent.rgt AND node.id = l.competence AND parent.id != 1 ORDER BY parent.lft) SEPARATOR \"<br />\\n\") AS competences I get this row: Crafts » Joinery Administration » Organization I want it like this: Administration » Organization Crafts » Joinery 回答1:

MySQL and GROUP_CONCAT() maximum length

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 05:41:11
问题 I\'m using GROUP_CONCAT() in a MySQL query to convert multiple rows into a single string. However, the maximum length of the result of this function is 1024 characters. I\'m very well aware that I can change the param group_concat_max_len to increase this limit: SET SESSION group_concat_max_len = 1000000; However, on the server I\'m using, I can\'t change any param. Not by using the preceding query and not by editing any configuration file. So my question is: Is there any other way to get the

Sqlite group_concat ordering

我们两清 提交于 2019-11-26 05:34:59
问题 In Sqlite I can use group_concat to do: 1...A 1...B 1...C 2...A 2...B 2...C 1...C,B,A 2...C,B,A but the order of the concatenation is random - according to docs. I need to sort the output of group_concat to be 1...A,B,C 2...A,B,C How can I do this? 回答1: Can you not use a subselect with the order by clause in, and then group concat the values? Something like SELECT ID, GROUP_CONCAT(Val) FROM ( SELECT ID, Val FROM YourTable ORDER BY ID, Val ) GROUP BY ID; 回答2: To be more precise, according to

GROUP_CONCAT ORDER BY

谁都会走 提交于 2019-11-26 05:27:27
问题 I\'ve a table like: +-----------+-------+------------+ | client_id | views | percentage | +-----------+-------+------------+ | 1 | 6 | 20 | | 1 | 4 | 55 | | 1 | 9 | 56 | | 1 | 2 | 67 | | 1 | 7 | 80 | | 1 | 5 | 66 | | 1 | 3 | 33 | | 1 | 8 | 34 | | 1 | 1 | 52 | I tried group_concat : SELECT li.client_id, group_concat(li.views) AS views, group_concat(li.percentage) FROM li GROUP BY client_id; +-----------+-------------------+-----------------------------+ | client_id | views | group_concat(li

MySQL Join two tables with comma separated values

懵懂的女人 提交于 2019-11-26 04:18:57
问题 I have 2 tables as below Notes Table ╔══════════╦═════════════════╗ ║ nid ║ forDepts ║ ╠══════════╬═════════════════╣ ║ 1 ║ 1,2,4 ║ ║ 2 ║ 4,5 ║ ╚══════════╩═════════════════╝ Positions Table ╔══════════╦═════════════════╗ ║ id ║ name ║ ╠══════════╬═════════════════╣ ║ 1 ║ Executive ║ ║ 2 ║ Corp Admin ║ ║ 3 ║ Sales ║ ║ 4 ║ Art ║ ║ 5 ║ Marketing ║ ╚══════════╩═════════════════╝ I am looking to query my Notes table and associate the \'forDepts\' column with values from the Positions table. The

MySQL DISTINCT on a GROUP_CONCAT()

て烟熏妆下的殇ゞ 提交于 2019-11-26 02:07:32
问题 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! 回答1: GROUP_CONCAT has DISTINCT attribute: SELECT GROUP_CONCAT(DISTINCT categories ORDER BY categories ASC SEPARATOR ' ') FROM table 回答2: Using DISTINCT will work SELECT GROUP_CONCAT(DISTINCT

How to use GROUP_CONCAT in a CONCAT in MySQL

喜欢而已 提交于 2019-11-26 01:28:43
问题 If I have a table with the following data in MySQL: id Name Value 1 A 4 1 A 5 1 B 8 2 C 9 how do I get it into the following format? id Column 1 A:4,5,B:8 2 C:9 I think I have to use GROUP_CONCAT . But I\'m not sure how it works. 回答1: select id, group_concat(`Name` separator ',') as `ColumnName` from ( select id, concat(`Name`, ':', group_concat(`Value` separator ',')) as `Name` from mytbl group by id, `Name` ) tbl group by id; You can see it implemented here : Sql Fiddle Demo. Exactly what

Strange duplicate behavior from GROUP_CONCAT of two LEFT JOINs of GROUP_BYs

坚强是说给别人听的谎言 提交于 2019-11-26 01:09:12
问题 Here is all my tables\' structure and the query (please focus on the last query, appended below) . As you see in the fiddle, here is the current output: +---------+-----------+-------+------------+--------------+ | user_id | user_name | score | reputation | top_two_tags | +---------+-----------+-------+------------+--------------+ | 1 | Jack | 0 | 18 | css,mysql | | 4 | James | 1 | 5 | html | | 2 | Peter | 0 | 0 | null | | 3 | Ali | 0 | 0 | null | +---------+-----------+-------+------------+-

What is the opposite of GROUP_CONCAT in MySQL?

对着背影说爱祢 提交于 2019-11-26 00:34:02
问题 I seem to come against this problem a lot, where I have data that\'s formatted like this: +----+----------------------+ | id | colors | +----+----------------------+ | 1 | Red,Green,Blue | | 2 | Orangered,Periwinkle | +----+----------------------+ but I want it formatted like this: +----+------------+ | id | colors | +----+------------+ | 1 | Red | | 1 | Green | | 1 | Blue | | 2 | Orangered | | 2 | Periwinkle | +----+------------+ Is there a good way to do this? What is this kind of operation