Skip to content

Why does "count" aggregate counts multiple time the same result ? #16698

Answered by ginsbach
Sixelayo asked this question in Q&A
Discussion options

You must be logged in to vote

Thank you for the questions @ayosten, I hope I'll be able to help.

count: This aggregate determines the number of distinct values of <expression> for each possible assignment of the aggregation variables.

Note the precise wording here: the distinct values for each possible assignment of the aggregation variables are counted - they do not have to be distinct across different assignments.

Consider the following example:

class SmallInt extends int {
  SmallInt() { this in [5 .. 15] }
}

int foo(SmallInt i) { result in [i - 1, i, 1] }

select count(SmallInt i | | foo(i))
  • There are eleven possible assignments of the aggregation variable i (5, 6, ..., 14, 15).
  • For each of those assignments, …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Sixelayo
Comment options

Answer selected by Sixelayo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants