GRUPA KONKATEDRA
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 |
Próbowałem 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.percentage) |
+-----------+-------------------+-----------------------------+
| 1 | 6,4,9,2,7,5,3,8,1 | 20,55,56,67,80,66,33,34,52 |
+-----------+-------------------+-----------------------------+
Ale chcę uporządkować widoki, jak:
+-----------+-------------------+----------------------------+
| client_id | views | percentage |
+-----------+-------------------+----------------------------+
| 1 | 1,2,3,4,5,6,7,8,9 | 52,67,33,55,66,20,80,34,56 |
+-----------+-------------------+----------------------------+
96
4 answers
Możesz użyć ORDER BY
wewnątrz funkcji GROUP_CONCAT
w następujący sposób:
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
220
Author: aleroot,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-16 09:20:31
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-16 09:20:31
Group_concat obsługuje własną klauzulę order by
Http://mahmudahsan.wordpress.com/2008/08/27/mysql-the-group_concat-function/
Więc powinieneś umieć pisać:
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
13
Author: TetonSig,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-12-25 19:53:33
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-12-25 19:53:33
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
8
Author: Virendra,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-12-25 20:00:05
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-12-25 20:00:05
W impali brak porządkowania w GROUP_CONCAT może być problematyczny, nad Coders ' co. mamy do tego jakieś obejście (potrzebujemy go dla Rax/Impala). Jeśli potrzebujesz wyniku GROUP_CONCAT z klauzulą ORDER BY w impali, spójrz na ten wpis na blogu: http://raxdb.com/blog/sorting-by-regex/
0
Author: JMS,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-06-06 16:30:59
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-06-06 16:30:59