Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7774361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:21:31+00:00 2026-06-01T17:21:31+00:00

I have two table (TABLE_EXAM,TABLE_RESULT). Here is value of my TABLE_RESULT. result_id exam_id question_id

  • 0

I have two table (TABLE_EXAM,TABLE_RESULT). Here is value of my 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        

I need to count how many correct_answer=’y’ where exam_id=2.
I try following code but it return 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;
}

In variable confirm_answer i pass “y”.
Give me some hint or reference.
Any help is appreciated.
Thanks in Advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:21:32+00:00Added an answer on June 1, 2026 at 5:21 pm
    select count(*) from TABLE_RESULT where correct_answer="y" and exam id=2;
    

    This is total number of rows which has value as y and exam id=2

    Just try to run this query and then just Add your Parameters to it.

    SELECT COUNT(*)FROM result WHERE exam_id =" + examId + " and correctAnswer ='" + confirmAnswer +"'");
    

    Above is your query which i have formatted.

    Hope this helps you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two table. OLDTABLE and NEWTABLE. I need to insert some data from
I have two tables that need the exact same values for denormalization purposes. Here's
I have two table and I need to copy the data across from SRCServiceUsers
I have two table TABLE_EXAM and TABLE_QUESTION. I fetch record using following code but
see jsbin if u seen my jsbin then i have two table hardcode table
I have two table like this table_CN (_id, name, phone, favorite, title) table_EN (_id,
i have two table: declare @t1 table (id int) declare @t2 table (id int)
I have two table first is TABLE_SUBJECT and second is TABLE_CHAPTER.Now i want to
I have two table views, when user clicks one cell of the first, second
I have two table cells, with dynamic content. Table cell one works fine, when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.