S02021
错误代码
S02021
报错信息
The HAVING clause after GROUP BY must be followed by a boolean expression. RefId:S02021
错误原因
在 group by 子句中,having 计算的结果必须是布尔表达式,若结果不是布尔表达式,则会出现该报错。如以下场景中,having
的结果不是一个布尔表达式,出现报错:
n = 10000
id = take(1..10, n)
value = take(1..10, n)
t = table(id, value)
a = 1.0
select max(value) from t group by id having a // throw exception
select max(value) from t group by id having value // throw exception
select max(value) from t group by id having max(value) != 0 // OK
解决办法
检查查询中的 having 条件,确保其计算结果是一个布尔表达式。