如何将 SQL 数据从一个视图转换为 Postgres 中的另一个视图
How do I convert SQL data from one view to this other view in Postgres
我 table 有这样的数据
id group order value
-------------------------
1 1 1 23
2 1 2 34
3 2 1 234
4 2 2 77
5 2 3 102
我想插入到 table 中,所以我每组一行,值显示一串以逗号分隔的值顺序。
id group value
----------------
1 1 23,34
2 2 234,77,102
我该怎么做?我正在使用 Postgres 9.3
我会看看 PostgreSQL 的 string_agg 聚合函数。
Postgres 支持 string_agg()
:
select row_number() over () as id, "group", string_agg(value, ',' order by "order")
from t
group by "group";
我 table 有这样的数据
id group order value
-------------------------
1 1 1 23
2 1 2 34
3 2 1 234
4 2 2 77
5 2 3 102
我想插入到 table 中,所以我每组一行,值显示一串以逗号分隔的值顺序。
id group value
----------------
1 1 23,34
2 2 234,77,102
我该怎么做?我正在使用 Postgres 9.3
我会看看 PostgreSQL 的 string_agg 聚合函数。
Postgres 支持 string_agg()
:
select row_number() over () as id, "group", string_agg(value, ',' order by "order")
from t
group by "group";