Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.
Dan Gorman edited this page Nov 29, 2018 · 2 revisions

The COUNT Function

Function Group: Statistical

COUNT returns the number of elements in an array, or a series of elements.

Syntax

COUNT(arg1, [arg2...])

  • arg1 can be a number, string or an array of numbers or strings (or anything that can be coerced into being a number)
  • arg2 is optional, and has the same restrictions as arg1
  • COUNT can take an arbitrary number of optional arguments

Uses

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.

Other Examples

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

Clone this wiki locally