Skip to content

Commit

Permalink
Better
Browse files Browse the repository at this point in the history
  • Loading branch information
nik9000 committed Jul 12, 2024
1 parent 75467ba commit c8fd7ea
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
16 changes: 14 additions & 2 deletions docs/reference/esql/functions/count.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,20 @@ include::{esql-specs}/stats.csv-spec[tag=docsCountWithExpression-result]
|===

[[esql-agg-count-or-null]]
To count the number of times an expression returns `TRUE`, use
`COUNT(<expression> OR NULL)`:
To count the number of times an expression returns `TRUE` use
a <<esql-where>> command to remove rows that shouldn't be included:

[source.merge.styled,esql]
----
include::{esql-specs}/stats.csv-spec[tag=count-where]
----
[%header.monospaced.styled,format=dsv,separator=|]
|===
include::{esql-specs}/stats.csv-spec[tag=count-where-result]
|===

To count the same stream of data based on two different expressions
use the pattern `COUNT(<expression> OR NULL)`:

[source.merge.styled,esql]
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,21 @@ word_count:long
// end::docsCountWithExpression-result[]
;

count_or_null
// tag::count-where[]
ROW n=1
| WHERE n < 0
| STATS COUNT(n)
// end::count-where[]
;

// tag::count-where-result[]
COUNT(n):long
0
// end::count-where-result[]
;


count_or_null
// tag::count-or-null[]
ROW n=1
Expand Down

0 comments on commit c8fd7ea

Please sign in to comment.