title: Sum of field with where condition of this field - Influxdb
body: <p>I want to get the sum of <code>result_code</code> where <code>result_code=0</code>.</p>
  
  <p>What I found is that querying without sum gives me result but adding the aggregation sum() and then I have 0 as a result.</p>
  
  <p>For those who want an understanding of the use case :
  I use telegraf to ping some internal IP address to check it's availability (pings every 10s with a timeout of 5s) and I want to get its uptime (<code>result_code=0</code>) per day.</p>
  
  <p>I have tried changing the field in the sum function but that doesn't work better.</p>
  
  <pre><code>SELECT sum("result_code") FROM "ping" WHERE ("url" = 'MyUrl') AND time &gt;= 1557957600000ms and result_code=0
  
  name: ping
  time                sum
  ----                ---
  1557957600000000000 0
  </code></pre>
  
  <pre><code>name: ping
  time                result_code
  ----                -----------
  1557988031000000000 0
  1557988040000000000 0
  ...
  </code></pre>
  
  <p>In my example I expect to have</p>
  
  <pre><code>name: ping
  time                sum
  ----                ---
  1557957600000000000 2
  </code></pre>