title: Android-SQLite: How to Count specific value from Column?
body: <p>I have two table (TABLE_EXAM,TABLE_RESULT). Here is value of my TABLE_RESULT.  </p>
  
  <pre><code>result_id   exam_id   question_id   correct_answer  
    1            2            4              y     
    2            2            5              y       
    3            2            6              n         
    4            2            7              y        
  </code></pre>
  
  <p>I need to count how many correct_answer='y' where exam_id=2.<br>
  I try following code but it return 0.  </p>
  
  <pre><code>public int calculateResult(int examId,String confirmAnswer)
  {
      int correctAnswer=0;
      try
      {
          SQLiteDatabase db=this.getWritableDatabase();
  
           String selectQuery=("select count(correctAnswer) from result where exam_id ='" + examId + "' and correctAnswer ='" + 'y' +"'" );
          // String selectQuery=("SELECT COUNT(*)FROM result WHERE exam_id ='" + examId + "' and correctAnswer ='" + confirmAnswer +"'" );            
            Cursor cursor = db.rawQuery(selectQuery, null);
          if(cursor.moveToLast())
          {
              correctAnswer=cursor.getInt(3);
          }
      }
      catch(Exception e)
      {
          e.printStackTrace();
      }
      return correctAnswer;
  }
  </code></pre>
  
  <p>In variable confirm_answer i pass "y".<br>
  Give me some hint or reference.<br>
  Any help is appreciated.<br>
  Thanks in Advance</p>