[英]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.