Skip to content

Commit

Permalink
MDL-30734 question engine: sum_usage_marks_subquery edge-case.
Browse files Browse the repository at this point in the history
When all qas in a useage are 'gaveup' state, it gives NULL, not 0.0, for the total.
  • Loading branch information
timhunt committed Dec 14, 2011
1 parent acb3bf8 commit 9831354
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion question/engine/datalib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -851,7 +851,11 @@ public function set_max_mark_in_attempts(qubaid_condition $qubaids, $slot, $newm
* @return string SQL code for the subquery. * @return string SQL code for the subquery.
*/ */
public function sum_usage_marks_subquery($qubaid) { public function sum_usage_marks_subquery($qubaid) {
return "SELECT SUM(qa.maxmark * qas.fraction) // To explain the COALESCE in the following SQL: SUM(lots of NULLs) gives
// NULL, while SUM(one 0.0 and lots of NULLS) gives 0.0. We don't want that.
// We always want to return a number, so the COALESCE is there to turn the
// NULL total into a 0.
return "SELECT COALESCE(SUM(qa.maxmark * qas.fraction), 0)
FROM {question_attempts} qa FROM {question_attempts} qa
JOIN {question_attempt_steps} qas ON qas.id = ( JOIN {question_attempt_steps} qas ON qas.id = (
SELECT MAX(summarks_qas.id) SELECT MAX(summarks_qas.id)
Expand Down

0 comments on commit 9831354

Please sign in to comment.