相关疑难解决方法(0)

Postgresql GROUP_CONCAT等价?

我有一个表,我想每个id拉一行,并且字段值连接在一起.

例如,在我的表中,我有这个:

TM67 | 4  | 32556
TM67 | 9  | 98200
TM67 | 72 | 22300
TM99 | 2  | 23009
TM99 | 3  | 11200
Run Code Online (Sandbox Code Playgroud)

我想输出:

TM67 | 4,9,72 | 32556,98200,22300
TM99 | 2,3    | 23009,11200
Run Code Online (Sandbox Code Playgroud)

在MySQL中,我能够使用聚合函数GROUP_CONCAT,但这似乎在这里不起作用...是否有等效的PostgreSQL,或其他方法来实现这一点?

sql postgresql group-concat string-aggregation

237
推荐指数
5
解决办法
14万
查看次数

如何从string_agg()中对结果进行排序

我有一张桌子:

CREATE TABLE tblproducts
(
productid integer,
product character varying(20)
)
Run Code Online (Sandbox Code Playgroud)

随着行:

INSERT INTO tblproducts(productid, product) VALUES (1, 'CANDID POWDER 50 GM');
INSERT INTO tblproducts(productid, product) VALUES (2, 'SINAREST P SYP 100 ML');
INSERT INTO tblproducts(productid, product) VALUES (3, 'ESOZ D 20 MG CAP');
INSERT INTO tblproducts(productid, product) VALUES (4, 'HHDERM CREAM 10 GM');
INSERT INTO tblproducts(productid, product) VALUES (5, 'CREAM 15 GM');
INSERT INTO tblproducts(productid, product) VALUES (6, 'KZ LOTION 50 ML');
INSERT INTO tblproducts(productid, product) VALUES (7, 'BUDECORT …
Run Code Online (Sandbox Code Playgroud)

sql postgresql string-aggregation

77
推荐指数
2
解决办法
7万
查看次数