# count

[Read this page in HTML](https://www.scopedb.io/docs/reference/functions/aggregate/count)

Counts rows or non-NULL values.

## Syntax

```scopeql
count()
count(<expr>)
```

## Arguments

| Argument | Type     | Description                                                                                 |
| -------- | -------- | ------------------------------------------------------------------------------------------- |
| `<expr>` | Any type | Optional input expression. Omit it to count every row; provide it to count non-NULL values. |

## Returns

Returns `int`. Returns 0 for empty input, or when `count(<expr>)` sees only NULL values.

## Examples

Count all checkout events and those with a buyer ID:

```scopeql
VALUES
    ('web', 'buyer-17'), ('web', NULL), ('web', 'buyer-42'),
    ('mobile', 'buyer-63'), ('mobile', NULL)
SELECT $0 AS channel, $1 AS buyer_id
GROUP BY channel
AGGREGATE count() AS events, count(buyer_id) AS identified_events
ORDER BY channel
```

```text
+---------+--------+-------------------+
| channel | events | identified_events |
+---------+--------+-------------------+
| mobile  | 2      | 1                 |
| web     | 3      | 2                 |
+---------+--------+-------------------+
```

`count(buyer_id)` counts non-NULL values, including repeated IDs. Use `count_distinct` to count distinct buyers.
