Skip to content
Browse files

Merge branch 'MDL-30734_21' of git://github.com/timhunt/moodle into M…

…OODLE_21_STABLE
  • Loading branch information...
2 parents 0006e0c + ba9cb08 commit dd98ec697cbf2dea8ce43927a3e87b2258d8d76a Sam Hemelryk committed Dec 19, 2011
Showing with 5 additions and 1 deletion.
  1. +5 −1 question/engine/datalib.php
View
6 question/engine/datalib.php
@@ -851,7 +851,11 @@ public function set_max_mark_in_attempts(qubaid_condition $qubaids, $slot, $newm
* @return string SQL code for the subquery.
*/
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
JOIN {question_attempt_steps} qas ON qas.id = (
SELECT MAX(summarks_qas.id)

0 comments on commit dd98ec6

Please sign in to comment.
Something went wrong with that request. Please try again.