> For the complete documentation index, see [llms.txt](https://couchbase.shujuwajue.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://couchbase.shujuwajue.com/n1ql-ji-chu-cao-zuo-jiao-cheng/n1qlji-chu/19aggregate-ju-he-han-shu.md).

# 19.COUNT() , AVG() 聚合函数

在下边的例子我们使用COUNT()函数来告诉我们有多少文档在桶里。

**COUNT() Query:**

```sql
SELECT COUNT(*) AS count
    FROM tutorial
```

结果:

```javascript
{
  "results": [
    {
      "count": 6
    }
  ]
}
```

**AVG() Query:**

```sql
SELECT COUNT(*) AS count, AVG(c.age) AS avg_age
FROM tutorial t
UNNEST t.children c
WHERE c.age > 10
```

结果：

```javascript
{
  "results": [
    {
      "avg_age": 18,
      "count": 4
    }
  ]
}
```
