Skip to content

Why is the result of "count" different from what I expected? #15759

Discussion options

You must be logged in to vote

count() determines the possible values of a variable.

from SmallInt i
select count(i)

from creates the variable i which is a value set of [1,2] and count is passed those values independently in the select. so 1 is only one value, and 2 is only one value. this is how the select statements are evaluated.

though select count(SmallInt i | | i) will result in 2 because you are using temporary variables and counting the possible values in the expression part of the aggregate, and then selecting that.

hope this helps. you could also just read: https://codeql.github.com/docs/ql-language-reference/expressions/#aggregations-1

Replies: 1 comment 2 replies

You must be logged in to vote
2 replies
@aibaars
Comment options

@ryokoCL
Comment options

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