【发布时间】:2019-03-10 06:59:55
【问题描述】:
我想列出每个客户购买的品牌。我有相同的“customer_id”字段反复出现,并带有他们在此代码中购买的不同品牌的名称(显示为列标题:“名称”)。我想按 customer_id 分组并显示每个 customer_id 的品牌列表。我收到错误消息:
“错误:函数 group_concat(字符变化,未知)不 存在 ^ 提示:没有函数匹配给定的名称和参数类型。你可能需要 添加显式类型转换。
CREATE TEMP TABLE customer_brandids AS
SELECT receipts.receipt_id, receipts.customer_id, receipt_item_details1.brand_id
FROM receipts
LEFT JOIN receipt_item_details1
ON receipts.receipt_id = receipt_item_details1.receipt_id;
SELECT customer_brandids.customer_id, customer_brandids.brand_id, brands.name, GROUP_CONCAT(brands.name,',')
FROM customer_brandids
INNER JOIN brands
ON customer_brandids.brand_id = brands.brand_id
GROUP by customer_id
【问题讨论】:
-
试试 string_agg。 group_concat 是不是mySQL?
-
您在Postgres manual 的哪个位置找到
group_concat?
标签: postgresql