title: Moodle gradebook export
body: <p>I'm trying to import student's gradebook marks from Moodle database, but I cannot find any details where category marks are stored or if they are calculated on the fly. If they are calculated, could I reproduce this calculation in a query?</p>
  
  <p>Thanks</p>
  
  <p>Edit: Thanks to Hipjea I've got my hands on ad-hock queries page. This is what I needed. But now I'm facing another issue: for some subjects the query does not return categories. It looks like gradbook setup is the same for all of them. Need some hing wht it could be. It looks like course is not liked to categories somehow.</p>
  
  <p>The query is:</p>
  
  <pre><code>SELECT DISTINCT gi.itemname
  FROM mdl_course AS c
      JOIN mdl_context AS ctx ON c.id = ctx.instanceid
      JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id
      JOIN mdl_user AS u ON u.id = ra.userid
      JOIN mdl_grade_grades AS gg ON gg.userid = u.id
      JOIN mdl_grade_items AS gi ON gi.id = gg.itemid
      JOIN mdl_course_categories AS cc ON cc.id = c.category
  WHERE  gi.courseid = c.id
      AND gi.itemname = 'Cycle 1'
      AND gi.itemtype IN ('category')
      AND c.id = 123
  </code></pre>