Skip to content

Commit 81e4fa3

Browse files
committed
Document topK and topKWeighted
1 parent a3e8923 commit 81e4fa3

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/content/docs/analytics/analytics-engine/sql-reference/aggregate-functions.mdx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,47 @@ Example:
204204
-- find the oldest value of <blob1>
205205
SELECT last_value(blob1) FROM my_dataset ORDER BY timestamp DESC
206206
```
207+
208+
## topK <Badge text="New" variant="tip" size="small" />
209+
210+
Usage:
211+
212+
```sql
213+
topK(N)(column)
214+
```
215+
216+
`topK` is an aggregation function which returns the most common `N` values of a column.
217+
218+
`N` is optional and defaults to `10`.
219+
220+
Example:
221+
222+
```sql
223+
-- find the 10 most common values of <double1>
224+
SELECT topK(double1) FROM my_dataset
225+
226+
-- find the 15 most common values of <blob1>
227+
SELECT topK(15)(blob1) FROM my_dataset
228+
```
229+
230+
## topKWeighted <Badge text="New" variant="tip" size="small" />
231+
232+
Usage:
233+
234+
```sql
235+
topKWeighted(N)(column, weight_column)
236+
```
237+
238+
`topKWeighted` is an aggregation function which returns the most common `N` values of a column, weighted by a second column.
239+
240+
`N` is optional and defaults to `10`.
241+
242+
Example:
243+
244+
```sql
245+
-- find the 10 most common values of <double1>, weighted by `_sample_interval`
246+
SELECT topKWeighted(double1, _sample_interval) FROM my_dataset
247+
248+
-- find the 15 most common values of <blob1>, weighted by `_sample_interval`
249+
SELECT topKWeighted(15)(blob1, _sample_interval) FROM my_dataset
250+
```

0 commit comments

Comments
 (0)