Reputation: 183
I am struggling with a Grails(Hibernate) query.
I have a table (ExamLog) that tracks each time an exam question is modified in a test bank.
The ExamLog table has the following attributes: logId(PK), exam(FK), question(FK), comments, oldMark, newMark, dateModified. The Exams table has the following attributes: examId(PK), questionsId(FK), lastUsed, versionCode ...etc, The Questions table has the following attributes: questionID(PK), description, difficultyLevel, avgPassed, ...etc.
My domains looks like this:
class ExamLog{
Exams exam;
Questions question;
String comments;
Integer oldMark;
Integer newMark;
String dateModified;
static belongsTo = [exam: Exams, question: Questions]
}
class Exams{
Question questions;
Integer versionCode;
Integer lastUsed;
}
class Questions{
String description;
Integer difficultyLevel;
Boolean avgPassed;
}
I am trying to get a list of questions for each exam in which avgPassed=false so that I can then count how many questions in the testbank have been failed;
I have looked at examples on StackOverflow but am still having difficulties. This is what I have tried but I am not getting the correct results with either method. Using sql:
ExamLog.executeQuery("Select exam_log.exam_id, count(avgPassed) from exam_log, question where exam_log.exam_id = question.exam_id group by(exam_log.exam_id");
Using Grails Hibernate Criteria:
def outstanding = ExamLog.createCriteria().list{
projections{
exams{
questions{
eq("avgPassed",false)
}
}
}
}
Upvotes: 1
Views: 44