如何在Oracle中聚合具有多个列的多行?
问题描述:
我有一个具有三列的表(名为“游戏”):天气,体育和客户如何在Oracle中聚合具有多个列的多行?
weather sports customer
sun volleyball Randy
sun volleyball Lau
sun gym Ryan
sun gym Rachel
表是
weather sports customer
sun volleyball Randy, Lau
sun gym Ryan, Rachel
我用以下LISTAGG命令但是它给了我“由表达式不是组”错误说
SELECT
weather, sports,
LISTAGG(customer, ',') WITHIN GROUP (ORDER BY sports) "Customer"
FROM games
GROUP BY customer;
答
的GROUP BY
需要包含未聚集列。他们定义结果集中的每一行:
SELECT weather, sports,
LISTAGG(customer, ',') WITHIN GROUP (ORDER BY sports) as Customers
FROM games
GROUP BY weather, sports;
谢谢你的工作。 –