我收到错误:
Ordered Analytical Function not allowed in group by clause
以下查询。
SELECT
CC.CASE_ID as CASE_ID,
FIRST_VALUE(CC.CASE_OWN_NM) OVER(PARTITION BY CC.CASE_ID )as FST_AGNT_CASE_OWN_NM,
FIRST_VALUE(CC.LSTMOD_BY_AGNT_PRFL_NM) OVER(PARTITION BY CC.CASE_ID)as FST_AGNT_PRFL_NM,
LAST_VALUE(CC.CASE_OWN_NM) OVER(PARTITION BY CC.CASE_ID) as LST_AGNT_CASE_OWN_NM,
LAST_VALUE(CC.LSTMOD_BY_AGNT_PRFL_NM) OVER(PARTITION BY CC.CASE_ID) as LST_AGNT_PRFL_NM,
case when CC.CASE_OWN_NM is not null then MIN(CC.REC_DTTM_PST) end as FST_AGNT_EDIT_DTTM,
case when CC.CASE_OWN_NM is not null then MAX(CC.REC_DTTM_PST) end as LST_AGNT_EDIT_DTTM,
case when CC.CASE_STS_CD='Open' then MIN(CC.REC_DTTM_PST) end as CASE_OPEN_DTTM,
case when CC.CASE_STS_CD in ( 'Closed', 'Auto Closed') then MIN(CC.REC_DTTM_PST) end as CASE_CLSE_OR_AUTO_CLSE_DTTM,
count( distinct CC.CASE_OWN_NM) as CASE_OWN_CHGS_IN_NUM,
--IIF((MAX(CC.CASE_TFR_TO_L2) = 1),'Yes','No') as ESCL_FL,
LAST_VALUE(CC.ESCL_RSN_TXT) OVER(PARTITION BY CC.CASE_ID )as ESCL_RSN_TXT,
LAST_VALUE( CC.ESCL_DTLS_TXT) OVER(PARTITION BY CC.CASE_ID ) as ESCL_DTLS_TXT
FROM EDW_KATAMARI_T.CNTCT_CASE CC
INNER JOIN EDW_KATAMARI_T.CNTCT_CASE_EXTN CCE
ON CC.CNTCT_CASE_APND_KEY = CCE.CNTCT_CASE_APND_KEY
INNER JOIN EDW_STAGE_COMN_SRC.STG_CNTCT_CASE_DELTA DELTA
on CC.CASE_ID = DELTA.CASE_ID
group by 1,2,3,4,5
sample 1
答案 0 :(得分:0)
SELECT CC.CASE_ID as CASE_ID, CC.FST_AGNT_CASE_OWN_NM, CC.FST_AGNT_PRFL_NM,
CC.LST_AGNT_CASE_OWN_NM, CC.LST_AGNT_PRFL_NM,CC.ESCL_RSN_TXT,CC.ESCL_DTLS_TXT,
case
when CC.CASE_OWN_NM is not null then MIN(CC.REC_DTTM_PST)
end as FST_AGNT_EDIT_DTTM,
case
when CC.CASE_OWN_NM is not null then MAX(CC.REC_DTTM_PST)
end as LST_AGNT_EDIT_DTTM,
case
when CC.CASE_STS_CD='Open' then MIN(CC.REC_DTTM_PST)
end as CASE_OPEN_DTTM,
case
when CC.CASE_STS_CD in ( 'Closed', 'Auto Closed') then MIN(CC.REC_DTTM_PST)
end as CASE_CLSE_OR_AUTO_CLSE_DTTM, count( distinct CC.CASE_OWN_NM) as CASE_OWN_CHGS_IN_NUM
FROM (select FIRST_VALUE(CC.CASE_OWN_NM) OVER(PARTITION BY CC.CASE_ID )as FST_AGNT_CASE_OWN_NM,
FIRST_VALUE(CC.LSTMOD_BY_AGNT_PRFL_NM) OVER(PARTITION BY CC.CASE_ID)as FST_AGNT_PRFL_NM,
LAST_VALUE(CC.CASE_OWN_NM) OVER(PARTITION BY CC.CASE_ID) as LST_AGNT_CASE_OWN_NM,
LAST_VALUE(CC.LSTMOD_BY_AGNT_PRFL_NM) OVER(PARTITION BY CC.CASE_ID) as LST_AGNT_PRFL_NM
,LAST_VALUE(CC.ESCL_RSN_TXT) OVER(PARTITION BY CC.CASE_ID )as ESCL_RSN_TXT,
LAST_VALUE( CC.ESCL_DTLS_TXT) OVER(PARTITION BY CC.CASE_ID ) as ESCL_DTLS_TXT
from EDW_KATAMARI_T.CNTCT_CASE ) CC INNER JOIN EDW_KATAMARI_T.CNTCT_CASE_EXTN CCE
ON CC.CNTCT_CASE_APND_KEY = CCE.CNTCT_CASE_APND_KEY INNER JOIN EDW_STAGE_COMN_SRC.STG_CNTCT_CASE_DELTA DELTA
on CC.CASE_ID = DELTA.CASE_ID
group by 1,2,3,4,5 ,6,7
sample 1