This repository was archived by the owner on Oct 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
COUNT
Dan Gorman edited this page Nov 29, 2018
·
2 revisions
COUNT returns the number of elements in an array, or a series of elements.
COUNT(arg1, [arg2...])
-
arg1can be a number, string or an array of numbers or strings (or anything that can be coerced into being a number) -
arg2is optional, and has the same restrictions asarg1 -
COUNTcan take an arbitrary number of optional arguments
Let's say we're given a response with lists of driver ids that looks like this:
{
"data":{
"driver_performance_ratings":{
"highest":98,
"lowest":20,
"fleet":[
30,
60,
55,
99
]
}
}
}If we want to find the number of the highest and lowest rated drivers, we can just use COUNT:
COUNT(data.driver_performance_ratings.highest, data.driver_performance_ratings.lowest)
This will return 2.
COUNT can also take arrays as arguments - so, in the event that a response could be either a single element or array, we could use COUNT thusly:
COUNT(data.driver_performance_ratings.highest, data.driver_performance_ratings.lowest, data.driver_performance_ratings.fleet ) => 6