Why is the result of "count" different from what I expected? #15759
-
a simple class definition:
When I run the following query:
the resule is 1. however, when using the "count" like this :
the result is 2. I don't quite understand why. and further I write :
the result is 0 and 1. if I modify the query to:
I get a result of 1. Why does a variable behave differently when it's defined in the "from" clause as opposed to directly in the "count"? Could someone explain this for me? Thank you for your assistance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
count() determines the possible values of a variable.
though hope this helps. you could also just read: https://codeql.github.com/docs/ql-language-reference/expressions/#aggregations-1 |
Beta Was this translation helpful? Give feedback.
count() determines the possible values of a variable.
from
creates the variable i which is a value set of [1,2] and count is passed those values independently in theselect
. 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