Processing of combining multiple rows of data into one field after grouping

It is often encountered that in the database query, the values ​​of another Chinese field in the record set obtained after being grouped by a certain field are merged. Generally, programming language technology is generally used for loop processing in the background. If the amount of data is large , the efficiency is relatively low, then let's take a look at how the database handles it by itself.
--MYSQL

SELECT T. group field, group_concat(T. join field)
from TABLENAME T
GROUP BY T. group field

The generated join fields are separated by commas.

--ORACLE
has a wmsys user in oracle. This user is the same as sys, system and other users. It was created when oracle was installed. It is mainly responsible for the management of oracle's daily work (WM: work manager).
The function at the beginning of wm is this functions under the user.

SELECT T. group field, WM_CONCAT (T. join field) AS NAME FROM TABLENAME T GROUP BY T. group field

The generated join fields are also separated by commas.

--ORACLE 11 is not verified, because the author does not have 11G locally, I hope comrades can verify
SELECT LISTAGG(T. join field, ',') WITHIN GROUP( ORDER BY T. group field) AS NAME FROM TABLENAME T

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327033792&siteId=291194637