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

  • Home
  • SEARCH
  • 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 6610593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:51:38+00:00 2026-05-25T19:51:38+00:00

I have 3 tables students, class and grades. I need to make a query

  • 0

I have 3 tables students, class and grades. I need to make a query that will count how many specific grades are for specific class. And also calculate average grade for specific class where grade 1 is not included (grades are 1,2,3,4,5).

Columns for the query should look like this:

Class  | Grade 1 |   Grade 2  |   Grade 3  |   Grade 4  |  Grade 5  |   Average (except 1)

I know how to get result for one specific grade:

select C.ClassName, count(G.Grade)
from Classes C, Grades G
where G.ClassesID = C.ClassesID and G.Grade = 1
group by C.ClassName

but how do I make a query to get all columns at once?

  • 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-25T19:51:39+00:00Added an answer on May 25, 2026 at 7:51 pm

    I would try SUBQUERY. If you use MSSQL you can try this:

    SELECT C.ClassName, 
    --Grade 1
    (SELECT COUNT(G1.Grade) 
    FROM Classes C1, Grades G1 
    WHERE G1.ClassesID = C1.ClassesID and G1.Grade = 1 and C1.ClassName = C.ClassName),
    --Grade 2
    (SELECT COUNT(G2.Grade) 
    FROM Classes C2, Grades G2 
    WHERE G2.ClassesID = C2.ClassesID and G2.Grade = 2 and C2.ClassName = C.ClassName),    
    -- Grade 3
    (SELECT COUNT(G3.Grade) 
    FROM Classes C3, Grades G3 
    WHERE G3.ClassesID = C3.ClassesID and G3.Grade = 3 and C3.ClassName = C.ClassName),
    --Grade 4
    (SELECT COUNT(G4.Grade) 
    FROM Classes C4, Grades G4 
    WHERE G4.ClassesID = C4.ClassesID and G4.Grade = 4 and C4.ClassName = C.ClassName),
    --Grade 5
    (SELECT COUNT(G5.Grade) 
    FROM Classes C5, Grades G5 
    WHERE G5.ClassesID = C5.ClassesID and G5.Grade = 5 and C5.ClassName = C.ClassName)
    -- Average (except 1)
    (SELECT SUM(GA.Grade) / COUNT(GA.Grade) 
    FROM Classes CA, Grades GA 
    WHERE GA.ClassesID = CA.ClassesID and GA.Grade NOT IN (1) and CA.ClassName = C.ClassName)
    
    FROM Classes C, Grades G
    WHERE G.ClassesID = C.ClassesID
    GROUP BY C.ClassName
    

    Aliases for the tables are not necessary. — Means comment.

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

Sidebar

Related Questions

I have a table that list students' grades per class. I want a result
Let's say I have a table that represents a super class, students . And
So I have two tables students (PK sID) and mentors (PK pID). This query
I have a table, say STUDENTS, that is related one-to-many to another table, CLASSES.
I have this SQL query: SELECT c.id as ID, c.class_name as CLASS, COUNT(e.student_id) AS
I have three tables CLASSES , CHILD_CLASSES , and STUDENTS . CLASSES looks like
I have two tables: subject and student. I'm trying to count the number of
I have a table that looks like this for about ~30 students: StudentID Course*
I have two objects (class, student) in a database with a many to many
Help a sqlite n00b out, please. I have two tables CREATE TABLE students (

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.