0

I was doing like the following query and received "not a single-group group function" error.

select distinct a.col1, 
       a.col2,
       rtrim(xmlagg(xmlelement(e, b.col1 ||',')).extract('//text()'), ','),
       rtrim(xmlagg(xmlelement(e, b.col2 ||',')).extract('//text()'), ',')
from table1 a
where a.col3 like '%string%'
left join table2 b on (a.pid = b.pid);

I did left join between table1 and table2 and I need to aggregate multiple rows into one row. So I wrote:

rtrim(xmlagg(xmlelement(e, b.col1 ||',')).extract('//text()'), ','),
rtrim(xmlagg(xmlelement(e, b.col2 ||',')).extract('//text()'), ',') 

But when I attempt to do this, I received an error:

ORA-00937 not a single-group group function

I am not using any aggregations in select statement. What should I do to write rtrim(... ) without the error?

Thanks in advance.

4

1 回答 1

0

您需要删除您的DISTINCTGROUPING改为使用,因为您使用聚合函数。

select a.col1, 
       a.col2,
       rtrim(xmlagg(xmlelement(e, b.col1 ||',')).extract('//text()'), ','),
       rtrim(xmlagg(xmlelement(e, b.col2 ||',')).extract('//text()'), ',')
from table1 a
where a.col3 like '%string%'
left join table2 b on (a.pid = b.pid)
GROUP BY a.col1, 
       a.col2
于 2015-05-09T03:37:16.780 回答