COUNT(*)

Counts the number of records that were aggregated. ‌

Syntax

COUNT(*) ‌

Arguments

none ‌

Returns

A number

Example

Data

[
   {
      "serverIp":"10.0.0.1",
      "time":1628894700000,
      "cpuUsage":52.3
   },
   {
      "serverIp":"10.0.0.1",
      "time":1628894760000,
      "cpuUsage":2.4
   },
   {
      "serverIp":"10.0.0.1",
      "time":1628894820000,
      "cpuUsage":99.3
   },
   {
      "serverIp":"10.0.0.1",
      "time":1628894880000,
      "cpuUsage":99.6
   },
   {
      "serverIp":"10.0.0.1",
      "time":1628894940000,
      "cpuUsage":12.3
   },
   {
      "serverIp":"10.0.0.1",
      "time":1628895000000,
      "cpuUsage":55
   },
   {
      "serverIp":"10.0.0.2",
      "time":1628894700000,
      "cpuUsage":2.3
   },
   {
      "serverIp":"10.0.0.2",
      "time":1628894760000
   },
   {
      "serverIp":"10.0.0.2",
      "time":1628894820000,
      "cpuUsage":9.3
   },
   {
      "serverIp":"10.0.0.2",
      "time":1628894880000,
      "cpuUsage":9.6
   },
   {
      "serverIp":"10.0.0.2",
      "time":1628894940000,
      "cpuUsage":2.3
   }
]

Query 1:

Count the number of entries for each serverip:

SET
   Unix_Time = UNIX_EPOCH_TO_DATE(data.time);
SELECT
   data.serverip AS serverip:STRING,
   COUNT(*) AS "count":BIGINT 
FROM
   "TIME_SERIES_w_NULLs" 
GROUP BY
   data.serverip

Results 1:

{
   "count_data_serverip":5,
   "serverip":"10.0.0.2"
}{
   "count_data_serverip":6,
   "serverip":"10.0.0.1"
}

Query 2:

Count the number of entries for each time interval:

SET
   Unix_Time = UNIX_EPOCH_TO_DATE(data.time);
SELECT
   COUNT(data.serverip) AS count_data_serverip:BIGINT,
   Unix_Time AS unix_time:TIMESTAMP 
FROM
   ""TIME_SERIES_w_NULLs"" 
GROUP BY
   Unix_Time

Results 2:

{
   "count":2,
   "date_time":1628894820000
}{
   "count":1,
   "date_time":1628895000000
}{
   "count":2,
   "date_time":1628894880000
}{
   "count":2,
   "date_time":1628894760000
}{
   "count":2,
   "date_time":1628894700000
}{
   "count":2,
   "date_time":1628894940000
}

COUNT COUNT_EACH COUNT_DISTINCT

Dialog

Last updated