@deepgoing’s idea is okay. In order to solve the problem of uid duplication and sorting, you can first do a distcint query, such as:
SELECT
wid,
SUBSTRING_INDEX(GROUP_CONCAT(uid ORDER BY id),',',5) AS 'uids'
FROM (
SELECT DISTINCT wid, uid
FROM demo_table
ORDER BY wid, uid
)
GROUP BY wid
Assume that the name of this table is tentatively demo_table
You can use the following statement to achieve your needs
@deepgoing’s idea is okay. In order to solve the problem of uid duplication and sorting, you can first do a distcint query, such as: