首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在配置单元中获取语义错误“表达式不在GROUP BY key 'Cust_intrl_ID‘中

在配置单元中获取语义错误“表达式不在GROUP BY key 'Cust_intrl_ID‘中
EN

Stack Overflow用户
提问于 2021-03-13 02:48:32
回答 1查看 28关注 0票数 0

以下查询在第4行(表达式不在GROUP BY键‘Cust_intrl_ID’中)中有错误:

代码语言:javascript
复制
SELECT
    Cust_intrl_ID,
    customer_no,
    cust_type_cd
FROM
    (
        SELECT
            Cust_intrl_ID,
            customer_no,
            cust_cust_type_cd,
            year(trxn_exctn_dt) year,
            month(trxn_exctn_dt) month,
            sum(w.trxn_base_am)
        FROM
            (
                SELECT
                    cust.Cust_intrl_ID Cust_intrl_id,
                    regexp_replace(w.cstm_4_tx, "^0+(?!$)", "") customer_no,
                    year(w.trxn_exctn_dt) year,
                    month(w.trxn_exctn_dt) month,
                    sum(w.trxn_base_am) amt,
                    ca.cust_acct_role_cd cust_acct_role_cd,
                    cust.cstm_4_tx cstm_4_tx,
                    ca.acct_intrl_id acct_intrl_id
                FROM
                    l4_amlmntcbnn.Wire_trxn w
                    INNER JOIN l4_amlmntcbnn.acct a on a.eap_as_of_dt = '2021-01'
                    and a.Acct_intrl_ID = w.Benef_acct_ID
                    and a.acct_type1_cd <> 'IPB'
                    and substring(a.jrsdcn_cd, 0, 2) <> 'LA'
                    INNER JOIN l4_amlmntcbnn.cust_acct ca on ca.eap_as_of_dt = a.eap_as_of_dt
                    and ca.Acct_intrl_ID = a.Acct_intrl_ID
                    INNER JOIN l4_amlmntcbnn.cust on ca.eap_as_of_dt = cust.eap_as_of_dt
                    and ca.cust_intrl_ID = cust.cust_intrl_ID
                    and cust.cust_type_cd = 'IND'
                WHERE
                    w.trxn_exctn_dt between '2020-07-01'
                    and '2020-12-31'
                    and w.frgn_trxn_fl = 'Y'
                UNION ALL
                SELECT
                    cust.Cust_intrl_ID,
                    regexp_replace(w.cstm_4_tx, "^0+(?!$)", "") customer_no,
                    year(w.trxn_exctn_dt) year,
                    month(w.trxn_exctn_dt) month,
                    sum(w.trxn_base_am) amt,
                    ca.cust_acct_role_cd cust_acct_role_cd,
                    cust.cstm_4_tx cstm_4_tx,
                    ca.acct_intrl_id acct_intrl_id
                FROM
                    l4_amlmntcbnn.Wire_trxn w
                    INNER JOIN l4_amlmntcbnn.acct a on a.eap_as_of_dt = '2021-01'
                    and a.Acct_intrl_ID = w.Orig_acct_ID
                    and a.acct_type1_cd <> 'IPB'
                    and substring(a.jrsdcn_cd, 0, 2) <> 'LA'
                    INNER JOIN l4_amlmntcbnn.cust_acct ca on ca.eap_as_of_dt = a.eap_as_of_dt
                    and ca.Acct_intrl_ID = a.Acct_intrl_ID
                    INNER JOIN l4_amlmntcbnn.cust on ca.eap_as_of_dt = cust.eap_as_of_dt
                    and ca.cust_intrl_ID = cust.cust_intrl_ID
                    and cust.cust_type_cd = 'IND'
                WHERE
                    w.trxn_exctn_dt between '2020-07-01'
                    and '2020-12-31'
                    and w.frgn_trxn_fl = 'Y'
            ) w
        GROUP BY
            Cust_intrl_ID,
            regexp_replace(w.cstm_4_tx, "^0+(?!$)", ""),
            year(w.trxn_exctn_dt),
            month(w.trxn_exctn_dt),
            ca.cust_acct_role_cd,
            cust.cstm_4_tx,
            ca.acct_intrl_id
        having
            sum(w.trxn_base_am) >= 9000
    ) t
GROUP BY
    Cust_intrl_ID,
    customer_no,
    cust_acct_role_cd,
    cstm_4_tx,
    acct_intrl_id
having
    count(*) >= 5
EN

回答 1

Stack Overflow用户

发布于 2021-03-13 03:43:48

这只是一种预感-但是group by子句试图对select子句中没有的列进行操作

代码语言:javascript
复制
SELECT
    Cust_intrl_ID,
    customer_no,
    cust_type_cd

..。

代码语言:javascript
复制
GROUP BY
    Cust_intrl_ID,
    customer_no,
    cust_acct_role_cd,
    cstm_4_tx,
    acct_intrl_id

另外,sum(w.trxn_base_am)没有别名-

作为一个旁注- count(*)可能不是这个查询的重点-但是如果您使用count(1),您会发现性能有所提高

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66605587

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档