Skip to content

Instantly share code, notes, and snippets.

@mikebuchanon
Created June 14, 2013 15:40
Show Gist options
  • Select an option

  • Save mikebuchanon/5782830 to your computer and use it in GitHub Desktop.

Select an option

Save mikebuchanon/5782830 to your computer and use it in GitHub Desktop.
Find Moodle quiz questions and answer texts that contain the word 'angel'
--find all moodle questions that have the term ANGEL in their text
SELECT t.shortname,
t.quiz_name,
mques.name "question_name",
replace(replace(mques.questiontext,'<','&lt'),'>','&gt') "question_text"
FROM
(SELECT mc.shortname,
mq.name "quiz_name",
regexp_split_to_table(mq.questions,',')::integer "question_id"
FROM mdl_course mc
JOIN mdl_quiz mq ON mq.course=mc.id
WHERE mc.category=1 and mq.questions is not null and mq.questions != '') t
JOIN mdl_question mques ON t.question_id=mques.id
WHERE mques.questiontext ILIKE '%angel%';
--find all moodle question answers that have the term ANGEL in their text
SELECT t.shortname,
t.quiz_name,
mques.name "quesiton_name",
replace(replace(mqa.answer,'<','&lt'),'>','&gt') "answer_text"
FROM
(SELECT mc.shortname,
mq.name "quiz_name",
regexp_split_to_table(mq.questions,',')::integer "question_id"
FROM mdl_course mc
JOIN mdl_quiz mq ON mq.course=mc.id
WHERE mc.category=1 and mq.questions is not null and mq.questions != '') t
JOIN mdl_question mques ON mques.id=t.question_id
JOIN mdl_question_answers mqa ON mqa.question=mques.id
WHERE mqa.answer ILIKE '%angel%';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment