Вопрос: имеется-ли в MySQL 4 возможность агрегатно суммировать строки, добавляя последующую в конец предыдущей (возможно с разделителем)? Этакий AGG_CONCAT_WS(separator,field)? Может кто решал подобную проблему?
This function returns a string result with the concatenated non-NULL values from a group. It returns NULL if there are no non-NULL values. The full syntax is as follows:
mysql> SELECT student_name,
-> GROUP_CONCAT(test_score)
-> FROM student
-> GROUP BY student_name;
Or:
mysql> SELECT student_name,
-> GROUP_CONCAT(DISTINCT test_score
-> ORDER BY test_score DESC SEPARATOR ' ')
-> FROM student
-> GROUP BY student_name;
In MySQL, you can get the concatenated values of expression combinations. You can eliminate duplicate values by using DISTINCT. If you want to sort values in the result, you should use ORDER BY clause. To sort in reverse order, add the DESC (descending) keyword to the name of the column you are sorting by in the ORDER BY clause. The default is ascending order; this may be specified explicitly using the ASC keyword. SEPARATOR is followed by the string value that should be inserted between values of result. The default is a comma (','). You can remove the separator altogether by specifying SEPARATOR ''.
You can set a maximum allowed length with the group_concat_max_len system variable. The syntax to do this at runtime is as follows, where val is an unsigned integer:
SET [SESSION | GLOBAL] group_concat_max_len = val;
If a maximum length has been set, the result is truncated to this maximum length.
GROUP_CONCAT() was added in MySQL 4.1.
Note: Before MySQL 4.1.6, there are some small limitations with GROUP_CONCAT() for BLOB and TEXT values when it comes to using DISTINCT together with ORDER BY. To work around this limitation, use MID(expr,1,255) instead.
Получилась неплохая udf-функция. Может кому пригодится. Как пользоваться - см. раздел родной майскуловской документации "Добавление новых функций в MySQL"
Вы не можете начинать темы Вы не можете отвечать на сообщения Вы не можете редактировать свои сообщения Вы не можете удалять свои сообщения Вы не можете голосовать в опросах Вы не можете вкладывать файлы Вы можете скачивать файлы