title: Content Resolver - How to sum up a column value for all rows using query
body: <p>I am working on a project using Content Provider for DB.<br>
  I am able to fetch all rows using the query mentioned below.<br>
  My problem is I want to sum up a column for all rows fetched.</p>
  
  <p>I am querying as :</p>
  
  <pre><code>String query = WorkTable.ENTRY_TIME + " = ?"
  String projection = "new String[]{WorkoutLogTable.STEPS}";
   Cursor cursor = getContentResolver()
                  .query(
                          LogProvider.WORK_LOG,
                          projection,
                          query,
                          new String[]{dateString},
                          null
                  );
  </code></pre>
  
  <p>I want the sum of <code>WorkoutLogTable.STEPS</code>. Projection needs <code>string[]</code> as parameter, so how can I sum up the STEPS value?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I used a projection: </p>
  
  <pre><code>String projection = new String[]{"sum(WorkoutLogTable.STEPS}) as total"};
  </code></pre>
  
  <p>But it's also not working.</p>
  
  <p><strong>Solution:</strong></p>
  
  <p>I was doing a mistake by making the whole part as string.<br>
  So I have resolved so: </p>
  
  <pre><code>String projection = new String[]{"sum(steps) as total"}; // steps is my column name and I was fetching it by WorkoutLogTable.STEPS which was wrong
  </code></pre>
  
  <p>Or another solution can be using Dynamic string (from <code>cricket_007</code> answer)</p>