I have 2 tables, #1 called TESTS, #2 RESULTS
#1 TESTS (TESTID, LEVELID)
#2 RESULTS (USERID, TESTID, SCORE)
I would like to get TWO COUNTS, #1 total tests for a level, and #2, total tests from RESULTS where score = 100 GROUP BY LEVELID
I have 15 levels, so I basically want to get results something like this
Level 1 - 15 tests, 3 perfect
Level 2 - 25 tests, 5 perfect
....
....
Level 15 - 75 tests, 8 perfect
How can I do this using 1 SQL statement and is that the best way to do it?
Thanks.
It’s a well-posed question and I think the right one to ask in this situation.
First do a join for tests and results:
Then extend it with another join on tests to get the level sum: