ClickHouse查询异常

169 阅读1分钟
SELECT      rt_dept_code_3,
            round(sum(amt)/100,3) as amt_t,--转成元
            case when sum(amt) = 0  then 0
            else round(sum(gross_profit)*100/sum(amt),2) end as gross_profit_per,--毛利率全部
            case when sum(amt_normal) = 0 then 0
            else round(sum(gross_profit_normal)*100/sum(amt_normal),2) end as gross_profit_normal_per,--毛利率正常
            case when sum(amt) = 0  then 0
            else round(sum(amt_normal)*100/sum(amt),2) end as amt_normal_per,--正常占比
            case when sum(amt_prom) = 0  then 0
            else round(sum(gross_profit_prom)*100/sum(amt_prom),2) end as gross_profit_prom_per,--毛利率促销
            case when sum(amt) = 0  then 0
            else round(sum(amt_prom)*100/sum(amt),2) end as amt_prom_per,--促销占比
            case when sum(amt_ci) = 0  then 0
            else round(sum(gross_profit_ci)*100/sum(amt_ci),2) end as gross_profit_ci_per,--毛利率印花
            case when sum(amt) = 0  then 0
            else round(sum(amt_ci)*100/sum(amt),2) end as amt_ci_per--印花占比
        FROM ads_arhv_gp_rt_summary_1m
Code: 215, e.displayText() = DB::Exception: Column `rt_dept_code_3` is not under aggregate function 
and not in GROUP BY (version 20.4.4.18 (official build))
  • select中的字段必须要放在聚合函数中 或者 在group by 中出现