Member Avatar for Sanjay_23

I have one table with questions and another table with correct answer
If any user attempt question then I need result with marks.

Screenshot1.png

I want result:-

Screenshot2.png

Thanks in advance!

Recommended Answers

All 3 Replies

What have you tried? You seem to have a set of related tables. How about writing out a plain language sentence or two on how you want your query to manipulate the various bits of data. I often find this helps to get my head around things.

Member Avatar for Sanjay_23

I have tried following query
select
sum(questions.marks)
from
questions
inner join answers on questions.question_id = answers.question_id
inner join user_quiz_attempt on answers.answer_id = user_quiz_attempt.answer_id
where
answers.is_true = 1
and user_quiz_attempt.user_id = 12/13

Incorrect result
user_id marks_obtained
12 10
13 15

I don't have your data or tables, so I can only do something off the top of my head...

I think you need a GROUP BY xxtable_namexx.user_id in order to sum properly. But you seem to allow multiple attempts, so how are you supposed to sum? Count all correct answers, regardless of previous incorrect attempts (I'm assuming this is how you want to do it)?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.