开发者社区> 问答> 正文

使用coalesce函数只要超过一个expression,就会报错

使用coalesce函数只要超过一个expression,就会报错:
FAILED: ODPS-0130071:Semantic analysis exception - Expression not in GROUP BY key : line 8:9 ''$.table''

sql如下:
SELECT
md5(concat(aid,bid)) as id
,aid
, bid
, sum(amountdue) as amountdue
, coalesce(

sum(regexp_count(get_json_object(extended_x, '$.table.tableParties'), '{')),
decode(get_json_object(extended_x, '$.table'), NULL, 0, 1)

) as tableparty
, decode(sum(headcount),null,0,sum(headcount) ) as headcount
, 'a' as pt
FROM e_orders
where pt='20170425'
group by aid, bid

展开
收起
123ya 2017-05-14 22:20:48 7143 0
1 条回答
写回答
取消 提交回答
  • 您好,group by 后面要把分组字段都要跟上,您表达
    coalesce(

    sum(regexp_count(get_json_object(extended_x, '$.table.tableParties'), '{')),
    decode(get_json_object(extended_x, '$.table'), NULL, 0, 1)

    ) as tableparty
    , decode(sum(headcount),null,0,sum(headcount) ) as headcount
    返回值实际上也是字段,需要把整个表达式写在group by 后面

    2019-07-17 21:10:10
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载