有这样一张表:
select * from liutest order by 1;
id | kw
----+--------
1 | big
1 | hello
2 | oracle
2 | small
2 | apple
3 | shit
(6 rows)
我想按id把kw拼接成一个字符串,在网上查到一种方法:
select id,
array_to_string
(
ARRAY (
SELECT kw
FROM liutest gi
WHERE gi.id = gd.id
),
', '
) AS group_concat
FROM liutest gd
ORDER BY
id;