2つのテーブル(TABLE_EXAM、TABLE_RESULT)があります。これが私のTABLE_RESULTの値です。
result_id exam_id question_id correct_answer
1 2 4 y
2 2 5 y
3 2 6 n
4 2 7 y
私はexam_id=2であるcorrect_answer='y'の数を数える必要があります。
次のコードを試してみましたが、0が返されます。
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;
}
変数confirm_answerで、「y」を渡します。
ヒントや参考資料を教えてください。
どんな助けでも大歓迎です。
前もって感謝します