分组

时间:2015-11-18 09:08:54

标签: teradata

我收到错误

  

分组条款中不允许使用Teradata Orderer分析功能

当我运行此查询时:

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,
    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 10

我尝试了answer by anwaar_hell并稍微修改了一些列,但我仍然收到错误:

  

子查询中不允许使用有序分析函数

查询:

SELECT
    distinct CC.CASE_ID as CASE_ID,
    CCC.FST_AGNT_CASE_OWN_NM,
    CCC.FST_AGNT_PRFL_NM,
    CCC.LST_AGNT_CASE_OWN_NM,
    CCC.LST_AGNT_PRFL_NM,
    CCC.FST_CHNL_NM,
    CCC.LST_CHNL_NM,
    CCC.LST_VEND_NM,
    case when MAX(CC.CASE_TFR_TO_L2)='1' then 'Yes' else 'No' end as ESCL_FL,
    case when CC.LSTMOD_BY_AGNT_ROLE_NM='L1' then count(distinct CC.LSTMOD_BY_AGNT_ROLE_NM) end as XFER_BTWN_L1_NUM,
    MAX(CC.CASE_SAVED_ORD_NUM) as SAVES_OR_MODS_ON_CASE_NUM,
    MIN(CC.REC_DTTM_PST) as FST_QUE_TIME_IN_SECS2,
    case when CC.RMTE_ASST_USED_IN>=1 then 'Yes' else 'No' end as RMTE_SESS_FL,
    case when CC.OUTB_CALL_TYPE_CD='Outbound' then 1 else 0 end as IS_OUTB_CALL_TYPE_IN,
    case when CC.L2CALL_BK_SCEHDULED_PST_DT is NOT NULL then 'Yes' else 'No' end as L2_OUTB_CALL_SCHD_FL,
    MAX(CC.L2CALL_BK_SCEHDULED_PST_DT) as L2_CLBCK_SCEHDULED_DTTM,
    CC.PU_DTTM as LMI_PU_DTTM,
    CC.CLS_DTTM as LMI_CLS_DTTM,
  ( 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,
        FIRST_VALUE(CC.CHNL_NM) OVER(PARTITION BY CC.CASE_ID ) as FST_CHNL_NM,
        LAST_VALUE(CC.CHNL_NM) OVER(PARTITION BY CC.CASE_ID) as LST_CHNL_NM,
        LAST_VALUE(CCE.VEND_NM) OVER(PARTITION BY CC.CASE_ID) as LST_VEND_NM
    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
    where
        CC.CASE_ID='23268760'
  )
group by
    1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17

1 个答案:

答案 0 :(得分:0)

您需要计算derive表中的第一个和最后一个值,然后按

分组
<Image source={require('./img/house.png')} style={styles.image}/>