Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions documentation/query/functions/aggregation.md
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,9 @@ SELECT payment_type, corr(price, quantity) FROM transactions GROUP BY payment_ty
- `count()` or `count(*)` - counts the number of rows irrespective of underlying
data.
- `count(column_name)` - counts the number of non-NULL values in a given column.
- `count(distinct column_name)` - counts the number of distinct non-NULL values
in a given column. This is identical to
[`count_distinct(column_name)`](#count_distinct).
Comment thread
jerrinot marked this conversation as resolved.

#### Parameters

Expand Down Expand Up @@ -774,9 +777,22 @@ SELECT payment_type, count(amount) FROM transactions;
| card | 67 |
| NULL | 4 |

Count distinct values using standard SQL syntax (identical to `count_distinct`):

```questdb-sql
SELECT payment_type, count(distinct counterparty) FROM transactions;
```

| payment_type | count |
| :----------- | :---- |
| cash | 3 |
| card | 23 |
| NULL | 5 |

:::note

`NULL` values are aggregated with `count()`, but not with `count(column_name)`
or `count(distinct column_name)`.

:::

Expand All @@ -790,6 +806,13 @@ SELECT payment_type, count(amount) FROM transactions;
`count_distinct(column_name)` - counts distinct non-`NULL` values in `varchar`,
`symbol`, `long256`, `UUID`, `IPv4`, `long`, `int` or `string` columns.

:::tip

`count_distinct` is available for backwards compatibility. We recommend using
the standard SQL syntax [`count(distinct column_name)`](#count) instead.

:::

#### Return value

Return value type is `long`.
Expand Down