Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: Workers Analytics Engine expands SQL support further
description: Workers Analytics Engine now supports more SQL functions for aggregation and for working with dates and times
date: 2025-11-12
products:
- workers-analytics-engine
---
You can now perform more powerful queries directly in [Workers Analytics Engine](https://developers.cloudflare.com/analytics/analytics-engine/) with a major expansion of our SQL function library.

Workers Analytics Engine allows you to ingest and store high-cardinality data at scale (such as custom analytics) and query your data through a simple SQL API.

Today, we've expanded Workers Analytics Engine's SQL capabilities with several new functions:

[**New aggregate functions:**](https://developers.cloudflare.com/analytics/analytics-engine/sql-reference/aggregate-functions/)
- `countIf()` - count the number of rows which satisfy a provided condition
- `sumIf()` - calculate a sum from rows which satisfy a provided condition
- `avgIf()` - calculate an average from rows which satisfy a provided condition

[**New date and time functions:**](https://developers.cloudflare.com/analytics/analytics-engine/sql-reference/date-time-functions/)
- `toYear()`
- `toMonth()`
- `toDayOfMonth()`
- `toDayOfWeek()`
- `toHour()`
- `toMinute()`
- `toSecond()`
- `toStartOfYear()`
- `toStartOfMonth()`
- `toStartOfWeek()`
- `toStartOfDay()`
- `toStartOfHour()`
- `toStartOfFifteenMinutes()`
- `toStartOfTenMinutes()`
- `toStartOfFiveMinutes()`
- `toStartOfMinute()`
- `today()`
- `toYYYYMM()`

## Ready to get started?
Whether you're building usage-based billing systems, customer analytics dashboards, or other custom analytics, these functions let you get the most out of your data. [Get started ](/analytics/analytics-engine/get-started/) with Workers Analytics Engine and explore all available functions in our [SQL reference documentation](/analytics/analytics-engine/sql-reference/).
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,57 @@ SELECT topKWeighted(double1, _sample_interval) FROM my_dataset
-- find the 15 most common values of <blob1>, weighted by `_sample_interval`
SELECT topKWeighted(15)(blob1, _sample_interval) FROM my_dataset
```

## countIf <Badge text="New" variant="tip" size="small" />

Usage:

```sql
countIf(<expr>)
```

`countIf` is an aggregation function that returns the number of rows in the results set,
but only counting rows where a provided expression evaluates to true.

Example:

```sql
-- return the number of rows where `double1` is greater than 5
countIf(double1 > 5)
```

## sumIf <Badge text="New" variant="tip" size="small" />

Usage:

```sql
sumIf(<expr>, <expr>)
```

`sumIf` is an aggregation function that returns the sum of a first expression across all rows in the results set,
but only including rows where a second expression evaluates to true.

Example:

```sql
-- return the sum of column `item_cost` of all items where another column `in_stock` is not zero
sumIf(item_cost, in_stock > 0)
```

## avgIf <Badge text="New" variant="tip" size="small" />

Usage:

```sql
avgIf(<expr>, <expr>)
```

`avgIf` is an aggregation function that returns the mean of an expression across all rows in the results set,
but only including rows where a second expression evaluates to true.

Example:

```sql
-- return the mean of column `item_cost` where another column `in_stock` is not zero
avgIf(item_cost, in_stock > 0)
```
Loading