SQL help needed

ryan256

Platinum Member
Jul 22, 2005
2,514
0
71
Ok... I'm attempting to find out the test_id numbers of tests that were passed but have more than 10 questions unanswered.
There are 2 tables. Test_questions contains all the tests and individual answers to each question therein. Any unanswered question will have answer_id_given as a NULL. The Tests table contains the result of the test, who took it, what time, ect.. but all I'm interested in is test_id (which should match with what is in test_questions) and final_result.
First thing I did was:
select * into testquestions_temp from testquestions where answer_id_given is null
This produced a table containing every unanswered question (154k+ rows, yikes!)
Next I was going to attempt to count the number of test_id that was greater than 10 where the corresponding test_id in the Tests table had a final_result of passed. But I can't seem to write that SQL query correctly :(
What I have so far (that doesn't work)
select * FROM testquestions_temp AS TQT JOIN
Tests AS T ON TQT.test_id = T.test_id
where (T.final_status = 'passed') and having (COUNT(TQT.test_id) > '10')
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
SELECT tests.test_id, COUNT(*)
FROM tests, testquestions
WHERE tests.test_id = testquestions.test_id
AND tests.final_status = 'passed'
AND testquestions.answer_id_given is null
GROUP BY tests.test_id
HAVING COUNT(*) > 10