Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9179351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:46:29+00:00 2026-06-17T17:46:29+00:00

In MOODLE, I’m using the following script to pull some numbers — and they

  • 0

In MOODLE, I’m using the following script to pull some numbers — and they come out fine:

SELECT
qc.name,
q.category,
SUM(IF(qs.grade = "1",1,0)) AS Correct,
SUM(IF(qs.grade = "0",1,0)) AS Wrong

FROM
mdl_question_states qs,
mdl_quiz_attempts qa,
mdl_quiz qz,
mdl_course c,
mdl_question q,
mdl_question_categories qc

WHERE
qa.id = qs.attempt
AND qs.event = 6
AND qa.quiz = qz.id
AND ((qz.name = 'Pre-Test') OR (qz.name = 'Post-Test'))
AND qz.course = c.id
AND q.id = qs.question
AND q.category = qc.id
AND q.category > 601

GROUP BY q.category

ORDER BY qc.name

My question is this: I want to have a column (after the ‘SUM(IF…’ columns) that are ‘Correct -AND- Pre-Test’ followed by ‘Correct -AND- Post-Test’.

What is the syntax to use to accomplish this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:46:30+00:00Added an answer on June 17, 2026 at 5:46 pm

    Try

    SUM(IF(sq.grade = '1' AND qz.name='pre-test', 1, 0)) AS cor_and_pre
    

    and similarly for the other value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Moodle: I am trying to run some Javascript from within the frame
I am working on Moodle 2.2.1 and have created dynamic.csv files using certain queries.
I am using moodle and I change location of my web site, but I
I am using the Moodle database to query the latest forum posts made by
I am trying to install Moodle 1.9 using XAMPP on a virtual machine running
With a single click this simple script will do a multi-logout of: Moodle Elgg
i am using Moodle and joomla , and i use joomdle , but i
I am using Moodle 2.3 and want to make blog posts viewable to the
I'm planning on installing Moodle in a server (using an Oracle 10.2 DB and
Here in srilanka we don't have much internet facilities, we are using Moodle in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.