Window Function COUNT
07 Jul 2019This article is an extension of the window function, to follow up on each of the window functions.
The COUNT
function will counts each row that contains non-NULL values for the given expression.
An example usage over the test data set would be:
We list the sale_date
and salesperson
out for every sale on record. The COUNT
partitions by the date of the sale made. This makes the sale_number
tell us what number the sale was for that given date.
sale_date | salesperson | sales_count |
---|---|---|
2018-05-02 | Bob | 1 |
2018-05-13 | Sally | 1 |
2018-05-13 | June | 2 |
2018-05-14 | John | 1 |
2018-05-25 | Bob | 1 |
2018-05-25 | Sally | 2 |
2018-05-26 | John | 1 |
2018-05-27 | John | 1 |
2018-05-27 | June | 2 |
2018-05-27 | June | 3 |
2018-06-02 | Sally | 1 |
2018-06-03 | John | 1 |
2018-06-03 | John | 2 |
2018-06-12 | John | 1 |
2018-06-13 | Bob | 1 |
2018-06-13 | Sally | 2 |
2018-06-15 | John | 1 |
2018-06-24 | Bob | 1 |
2018-06-24 | Sally | 2 |
2018-06-29 | John | 1 |
Taking 2018-05-27
, we can see that John got the first sale, June got the second and third.