title: InfluxDB average of distinct count over time
body: <p>Using Influx DB v0.9, say I have this simple query:</p>
  
  <pre><code>select count(distinct("id")) FROM "main" WHERE time &gt; now() - 30m and time &lt; now() GROUP BY time(1m)
  </code></pre>
  
  <p>Which gives results like:</p>
  
  <pre><code>08:00 5
  08:01 10
  08:02 5
  08:03 10
  08:04 5
  </code></pre>
  
  <p>Now I want a query that produces points with an average of those values over 5 minutes.  So the points are now 5 minutes apart, instead of 1 minute, but are an average of the 1 minute values.  So the above 5 points would be 1 point with a value of the result of (5+10+5+10+5)/5.</p>
  
  <p>This does not produce the results I am after, for clarity, since this is just a count, and I'm after the average.</p>
  
  <pre><code>select count(distinct("id")) FROM "main" WHERE time &gt; now() - 30m and time &lt; now() GROUP BY time(5m)
  </code></pre>
  
  <p>This doesn't work (gives errors):</p>
  
  <pre><code>select mean(distinct("id")) FROM "main" WHERE time &gt; now() - 30m and time &lt; now() GROUP BY time(5m)
  </code></pre>
  
  <p>Also doesn't work (gives error):</p>
  
  <pre><code>select mean(count(distinct("id"))) FROM "main" WHERE time &gt; now() - 30m and time &lt; now() GROUP BY time(5m)
  </code></pre>
  
  <p>In my actual usage "id" is a string (content, not a tag, because count distinct not supported for tags in my version of InfluxDB).</p>