अपने परीक्षण के सभी छात्र स्कोर प्राप्त करने के लिए इस कथन का उपयोग करें।
SELECT sq.stdid, sq.testid, COUNT(*) AS correctAnswers,
SUM(q.marks) AS studentScore, (SELECT SUM(marks) FROM question
WHERE testid=$_REQUEST['testid']) AS totalScore
FROM question q, studentquestion sq
WHERE sq.testid=$_REQUEST['testid'] AND q.testid = sq.testid
AND q.qnid = sq.qnid AND sq.answered = 'answered'
AND q.correctanswer = sq.stdanswer GROUP BY sq.stdid;
आप प्रतिशत की गणना करने के लिए एक PHP चर बना सकते हैं। उदाहरण के लिए:
$scorePercentage = $r3['studentScore'] / $r3['totalScore'] * 100;
या
$scorePercentage = $r3['studentScore'] .'/'. $r3['totalScore'];
// Output: echo $scorePercentage;
60
60/100
अब स्कोर प्रतिशत प्राप्त करने के लिए इस SQL कथन का उपयोग करें:
SELECT sq.stdid, sq.testid, COUNT(*) AS correctAnswers,
(SUM(q.marks) / (SELECT SUM(marks) FROM question WHERE testid=1) * 100)
AS studentScorePercentage FROM question q, studentquestion sq
WHERE sq.testid=$_REQUEST['testid'] AND q.testid = sq.testid AND q.qnid = sq.qnid
AND sq.answered = 'answered' AND q.correctanswer = sq.stdanswer
GROUP BY sq.stdid;
उपरोक्त परिणामों के साथ SQLFiddle यहाँ:http://sqlfiddle.com/#!9/8d47c/10