[英]SQL Listagg function - error
我的LISTAGG
功能有問題。 我一直收到錯誤ORA-00937:不是單個組功能 。 我已經搜索了這個錯誤,但仍然不清楚錯誤是什么。
場景 :我有一個段表。 一個細分可以分配多個人(一對多)。 我需要我的輸出/報告來顯示一列中的段號和另一列中的用戶列表。
查詢 :
select fcs.nld_flood_control_segment_id
, fcs.fc_segment_name
, fcs.fc_segment_abbrev_name
, LISTAGG(ps.first_name|| ' ' ||ps.last_name, ', ') within group (ORDER BY fcs.nld_flood_control_segment_id, ps.last_name) "ListOfReps"
from nld_flood_control_segments fcs
, nld_fc_segment_person_xref xr
, persons ps
where fcs.nld_flood_control_segment_id = :P1_id
and :P1_id = xr.nld_flood_control_segment_id
and xr.person_id = ps.person_id
order by nld_flood_control_segment_id asc
;
任何幫助將不勝感激。 提前致謝。
LISTAGG函數具有以下語法結構:
LISTAGG( [,]) WITHIN GROUP (ORDER BY ) [OVER (PARTITION BY )]
LISTAGG是一個聚合函數,可以選擇用作分析(即可選的OVER()子句)。 以下要素是強制性的:
the column or expression to be aggregated;
the WITHIN GROUP keywords;
the ORDER BY clause within the grouping.
例:
LISTAGG(ename, ',') WITHIN GROUP (ORDER BY ename) AS employees
請嘗試以下操作,看看它是否能滿足您的需求。
LISTAGG(ps.first_name|| ' ' ||ps.last_name, ',') within group (ORDER BY ps.first_name|| ' ' ||ps.last_name) "ListOfReps"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.