---
source_url: https://docs.dolphindb.cn/zh/error_codes/S02021.html
fetched_at: 2026-05-19T09:09:36Z
category: error_codes
title: S02021
sha1: 7031948429eb3eed64d9aaf9f88e667908327297
---

# S02021

## 错误代码

S02021

## 报错信息

The HAVING clause after GROUP BY must be followed by a boolean expression.
RefId:S02021

## 错误原因

在 group by 子句中，having 计算的结果必须是布尔表达式，若结果不是布尔表达式，则会出现该报错。如以下场景中，`having`的结果不是一个布尔表达式，出现报错：

```dolphindb
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 条件，确保其计算结果是一个布尔表达式。
