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 中出现