我有一张表格:
CREATE TABLE tblproducts
(
productid integer,
product character varying(20)
)
使用行:
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 200 Rotocap');
如果我在 tblproducts
上执行 string_agg()
:
SELECT string_agg(product, ' | ') FROM "tblproducts"
它将返回以下结果:
CANDID POWDER 50 GM | ESOZ D 20 MG CAP | HHDERM CREAM 10 GM | CREAM 15 GM | KZ LOTION 50 ML | BUDECORT 200 Rotocap
我该如何按照ORDER BY product
的顺序排序聚合字符串呢?
我正在使用PostgreSQL 9.2.4。
string_agg
并不能直接跳转到相关内容。 - Manngo