MySQL 有 group-concat function,能將 group by 後的資料合併,方便查詢、處理。
例如
mysql> select id, group_concat(arr) from (
-> select 1 as id, 'orange' as arr
-> union all
-> select 1, 'banana'
-> union all
-> select 2, 'apple'
-> union all
-> select 1, 'banana'
-> union all
-> select 3, 'peach'
-> union all
-> select 1, 'grava'
-> union all
-> select 4, 'pineapple'
-> union all
-> select 4, 'pear'
-> ) as f
-> group by id;
+----+----------------------------+
| id | group_concat(arr) |
+----+----------------------------+
| 1 | banana,grava,orange,banana |
| 2 | apple |
| 3 | peach |
| 4 | pineapple,pear |
+----+----------------------------+
4 rows in set (0.00 sec)
然而這畢竟是 MySQL 特有的 function, clickhouse 並無此 function,要做到同樣的事就得用其他 function 來處理