[英]Oracle SQL: rtrim and group by
我在执行以下查询,但收到“不是单组群组函数”错误。
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);
我没有在table1和table2之间加入连接,我需要将多行汇总为一行。 所以我写道:
rtrim(xmlagg(xmlelement(e, b.col1 ||',')).extract('//text()'), ','),
rtrim(xmlagg(xmlelement(e, b.col2 ||',')).extract('//text()'), ',')
但是,当我尝试执行此操作时,出现了一个错误:
ORA-00937 not a single-group group function
我在select语句中没有使用任何聚合。 我应该怎么写而没有错误的rtrim(...)?
提前致谢。
您需要删除DISTINCT
并改为使用GROUPING
,因为您使用了聚合函数。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.