GROUP_CONCAT is a function which concatenates/merges the data from multiple rows into one field. It is a GROUP BY function which returns a string if the group contains at least 1 non-null value, if it does not, it returns a Null value.
Show activity on this post. 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.
You can use ORDER BY
inside the GROUP_CONCAT
function in this way:
SELECT li.client_id, group_concat(li.percentage ORDER BY li.views ASC) AS views,
group_concat(li.percentage ORDER BY li.percentage ASC)
FROM li GROUP BY client_id
The group_concat supports its own order by clause
http://mahmudahsan.wordpress.com/2008/08/27/mysql-the-group_concat-function/
So you should be able to write:
SELECT li.clientid, group_concat(li.views order by views) AS views,
group_concat(li.percentage order by percentage)
FROM table_views GROUP BY client_id
Try
SELECT li.clientid, group_concat(li.views ORDER BY li.views) AS views,
group_concat(li.percentage ORDER BY li.percentage)
FROM table_views li
GROUP BY client_id
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function%5Fgroup-concat
In IMPALA, not having order in the GROUP_CONCAT can be problematic, over at Coders'Co. we have some sort of a workaround for that (we need it for Rax/Impala). If you need the GROUP_CONCAT result with an ORDER BY clause in IMPALA, take a look at this blog post: http://raxdb.com/blog/sorting-by-regex/
You can use SEPARATOR and ORDER BY inside the GROUP_CONCAT function in this way:
SELECT li.client_id, group_concat(li.percentage ORDER BY li.views ASC SEPARATOR ',')
AS views, group_concat(li.percentage ORDER BY li.percentage ASC SEPARATOR ',') FROM li
GROUP BY client_id;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With