如何在Oracle中将多行合并为一行?

如何在Oracle中将多行合并为一行?,oracle,oracle11g,Oracle,Oracle11g,我如何在oracle中执行以下操作 输入 我希望在第2列和第3列中基于第1列合并为一行。结果应该是这样的 输出: 检查下面的查询。大多数情况下,它应该在你的情况下工作。它可能不会立即执行,请根据您的要求进行修改 SELECT id, LISTAGG (unit || ' ' || unit_description, ', ') WITHIN GROUP (ORDER BY unit, unit_description) FROM ( SELEC

我如何在oracle中执行以下操作

输入

我希望在第2列和第3列中基于第1列合并为一行。结果应该是这样的

输出:


检查下面的查询。大多数情况下,它应该在你的情况下工作。它可能不会立即执行,请根据您的要求进行修改

SELECT id, LISTAGG (unit || ' ' || unit_description, ', ') WITHIN GROUP (ORDER BY unit, unit_description) FROM ( SELECT id, unit_description, SUM (unit) AS unit FROM table1 GROUP BY id, unit_description) GROUP BY id;
到目前为止你做了什么?你可以从小组学习开始。
id  | unit details
12 70 KWh , 100 days
15 80 KWh
SELECT id, LISTAGG (unit || ' ' || unit_description, ', ') WITHIN GROUP (ORDER BY unit, unit_description) FROM ( SELECT id, unit_description, SUM (unit) AS unit FROM table1 GROUP BY id, unit_description) GROUP BY id;