How to get the number of entries in a measurement

This works as long as no field or tag exists with the name count:

SELECT SUM(count) FROM (SELECT *,count::INTEGER FROM MyMeasurement GROUP BY count FILL(1))

If it does use some other name for the count field. This works by first selecting all entries including an unpopulated field (count) then groups by the unpopulated field which does nothing but allows us to use the fill operator to assign 1 to each entry for count. Then we select the sum of the count fields in a super query. The result should look like this:

name: MyMeasurement
----------------
time    sum
0       47799

It's a bit hacky but it's the only way to guarantee a count of all entries when no field exists that is always present in all entries.


I suppose cartId is a tag rather than a field value? count() currently can't be used on tag and time columns. So if your status is a non-tag column (a field), do the count on that.

EDIT:

Reference

Tags:

Influxdb