-
Notifications
You must be signed in to change notification settings - Fork 323
Aggregate combinators examples #3446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Aggregate combinators examples #3446
Conversation
…n favour of only the most common ones
…into aggregate_combinators_examples_most_popular
…into aggregate_combinators_examples_most_popular
@Blargian is attempting to deploy a commit to the ClickHouse Team on Vercel. A member of the Team first needs to authorize it. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Skipped Deployments
|
FROM sales; | ||
``` | ||
|
||
The `avgIf` function will calculate the average amount only for rows where `is_successful = 1`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems out of place
``` | ||
|
||
Let's get the average wage of the people whose age lies in the intervals of `[30,60)` | ||
and `[60,75)`. Since we use integer representation for age, we get ages in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
] not )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is ) meant to imply inclusive?
('Brian', 60, 16.0); | ||
``` | ||
|
||
Let's count all the people whose age lies in the intervals of `[30,60)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok i assume same as above
GROUP BY URLDomain | ||
ORDER BY URLDomain ASC | ||
LIMIT 20; | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add to sql.clickhouse.com repo please!
|
||
The [`SimpleState`](/sql-reference/aggregate-functions/combinators#-simplestate) combinator can be applied to the [`min`](/sql-reference/aggregate-functions/reference/min) | ||
function to return the minimum value across all input values. It returns the | ||
result with type `SimpleAggregateState`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
link to SimpleAggregateState and maybe say we simple is useful (i.e. its lighter than full aggregatestate but limited to certain functions)
```sql | ||
SELECT | ||
post_id, | ||
sumSimpleState(upvotes) AS total_upvotes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems wrong
Create a materialized view with `SimpleAggregateFunction` type columns: | ||
|
||
```sql | ||
CREATE MATERIALIZED VIEW vote_totals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create aggregate table seperately from MV for best practice
SELECT | ||
post_id, | ||
sumSimpleState(upvotes) AS total_upvotes, | ||
sumSimpleState(downvotes) AS total_downvotes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure we need these sumSimpleState
When you use `sumSimpleState(column)`: | ||
- It directly extracts the stored sum value without doing any additional | ||
aggregation. | ||
- The result is of type `SimpleAggregateFunction(sum, Int64)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesnt make sense, why do this?
AS | ||
SELECT | ||
post_id, | ||
toUInt32(vote_type = 'upvote') AS upvotes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state here
Summary
Adds examples of common aggregate function combinator functions.
Checklist