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 6971243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:48:54+00:00 2026-05-27T16:48:54+00:00

I have 2 tables, #1 called TESTS, #2 RESULTS #1 TESTS (TESTID, LEVELID) #2

  • 0

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.

  • 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-05-27T16:48:55+00:00Added an answer on May 27, 2026 at 4:48 pm

    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:

     SELECT
        t.level,
        SUM(CASE WHEN r.score = 100 THEN 1 ELSE 0 END) AS perfectcount
     FROM tests t
     JOIN results r
        ON t.testid = r.testid
     GROUP BY t.testid
    

    Then extend it with another join on tests to get the level sum:

     SELECT t.level,
         COUNT(*) AS levelcount,
         t0.perfectcount
     FROM tests AS t
     JOIN {
         SELECT
            t.level,
            SUM(CASE WHEN r.score = 100 THEN 1 ELSE 0 END) AS perfectcount
         FROM tests t
         JOIN results r
            ON t.testid = r.testid
         GROUP BY t.testid
    ) AS t0
        ON t.level = t0.level
    GROUP BY t.level
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have two tables called A (fields: id, phase, name) and B(fields: id,
I have two tables, one called cart and one called items. Now I want
I have two tables in my database, called ratings and movies . Ratings: |
So i'm having this problem. I have two tables (Oracle), one is called Destination
I have 3 tables called radio, song, and artist controlled by favorite. Now I
I have some tables. These tables all have one column in common called 'classified_id':
SQL Server 2008 Database Question. I have 2 tables, for arguments sake called Customers
I have a CSS class called grid which I place on my tables. I
I have a couple of tables in my database, one called Task , and
I have an application managing software tests and a class called TestResult: class TestResult

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.