1

您好我有一个查询,我需要删除或格式化代码的输出显示。请看下面:

询问:

select rfc."NUMBER",
ag.current_pending_groups
from smspadm.cm3rm1 rfc, smspadm.tv_approval_vw appr, smspadm.approvala1 ag
Order By rfc."NUMBER"

当前结果:

NUMBER  CURRENT_PENDING_GROUPS

C301609 Comm/AT&T Vert DCAB
C302023 Collections DCAB
C302023 Comm/AT&T Vert DCAB
C302023 Fin-D2C-DNB DCAB
C302023 Interactive Recording DCAB
C302103 Collections DCAB
C302103 Wintel Server DCAB
C302103 Fin-D2C-DNB DCAB
C301813 GTHRA Vert DCAB
C301813 Tech Vert DCAB

期望的结果:要么:

NUMBER  CURRENT_PENDING_GROUPS

C301609 Comm/AT&T Vert DCAB
C302023 Collections DCAB, Comm/AT&T Vert DCAB, Fin-D2C-DNB DCAB
C302103 Collections DCAB, Wintel Server DCAB, Fin-D2C-DNB DCAB
C301813 GTHRA Vert DCAB, Tech Vert DCAB

或者应该是这样的:

NUMBER  CURRENT_PENDING_GROUPS

C301609 Comm/AT&T Vert DCAB
C302023 Collections DCAB
        Comm/AT&T Vert DCAB
        Fin-D2C-DNB DCAB
        Interactive Recording DCAB
C302103 Collections DCAB
        Wintel Server DCAB
        Fin-D2C-DNB DCAB
C301813 GTHRA Vert DCAB
        Tech Vert DCAB

我应该使用什么查询来获得这个结果?

4

2 回答 2

1
SELECT rfc."NUMBER",
  LISTAGG(ag.current_pending_groups, ', ')
   WITHIN GROUP (ORDER BY rfc."NUMBER") "CURRENT_PENDING_GROUPS"
   FROM smspadm.cm3rm1 rfc, smspadm.tv_approval_vw appr, smspadm.approvala1 ag
   GROUP BY rfc."NUMBER";


SELECT rfc."NUMBER",
   wm_concat(ag.current_pending_groups)
   FROM smspadm.cm3rm1 rfc, smspadm.tv_approval_vw appr, smspadm.approvala1 ag
   GROUP BY rfc."NUMBER";
于 2013-03-18T18:04:34.157 回答
0

第一个变体

select 
  rfc."NUMBER",
  wm_concat(ag.current_pending_groups)  -- for 10g
  -- listagg(ag.current_pending_groups,',') within group (order by ag.current_pending_groups)  -- for 11g
  as CURRENT_PENDING_GROUPS
from smspadm.cm3rm1 rfc, smspadm.tv_approval_vw appr, smspadm.approvala1 ag
group by rfc."NUMBER"
Order By rfc."NUMBER"

第二种变体

select
  case when
    row_number() over (partition by rfc."NUMBER" order by ag.current_pending_groups) = 1
  then
    rfc."NUMBER"
  end as "NUMBER",
  ag.current_pending_groups
from smspadm.cm3rm1 rfc, smspadm.tv_approval_vw appr, smspadm.approvala1 ag
Order By rfc."NUMBER", ag.current_pending_groups
于 2013-03-18T15:20:43.463 回答