I have the following sql code to output total. Though it does not produce any error, but not the desired result.

Select regd, Section, Test_date,
SUM(IF(t_scored IS NULL,0,t_scored)+IF(w_scored IS NULL,0,w_scored)+IF(f_scored IS NULL,0,f_scored)+IF(cce_scored IS NULL,0, cce_scored)) as maks
FROM

(SELECT regd as regd, Subject as Subject, Section as Section, Test_date as Test_date,
SUM(CASE WHEN Name_of_exam IN (‘First Unit Exam’, ‘Second Unit Exam’, ‘Third Unit Exam’)
THEN Mark_score
END)/SUM(CASE WHEN Name_of_exam IN (‘First Unit Exam’, ‘Second Unit Exam’, ‘Third Unit Exam’)
THEN Full_Mark
END)*25 AS t_scored,

SUM(CASE WHEN Name_of_exam IN (‘First Term Weekly Test’, ‘Second Term Weekly Test’, ‘Third Term Weekly Test’, ‘Final Term Weekly Test’)
THEN Mark_score
END)/SUM(CASE WHEN Name_of_exam IN (‘First Term Weekly Test’, ‘Second Term Weekly Test’, ‘Third Term Weekly Test’, ‘Final Term Weekly Test’)
THEN Full_Mark
END)*25 AS w_scored,

SUM(CASE WHEN Name_of_exam = ‘Final Unit Exam’
THEN Mark_score
END)/SUM(CASE WHEN Name_of_exam = ‘Final Unit Exam’
THEN Full_Mark
END)*25 AS f_scored,

SUM(CASE WHEN Name_of_exam = ‘Final Unit Exam’
THEN (Mark_score)
END) AS score_m,

SUM(CASE WHEN Name_of_exam = ‘CCE’
THEN Mark_score
END)/SUM(CASE WHEN Name_of_exam = ‘CCE’
THEN Full_Mark
END)*25 AS cce_scored

FROM cvexam
WHERE regd=’2055′ AND Subject not in (‘GK’,’Spelling’)
)t

I am working on this code for a month now. I still could not find the problem. As the schema is too large I could not paste all the data in sql fiddle, Here is the sqlfiddle link: Sample

I would feel very much happy if you can help me find the solution.

Read more here: Why is this sql code not producing desired result?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: