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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:20:54+00:00 2026-05-26T06:20:54+00:00

I have been playing around with code for a while now, and I have

  • 0

I have been playing around with code for a while now, and I have come across a problem where I must get the amount of certain fields where the average is above a certain amount , grouped by two fields from different tables

Here is my Code and expectations

SELECT C.Course,S.Name, COUNT(*) as Average FROM Students S
INNER JOIN Student_Modules SM ON
SM.StudentID = S.ID
INNER JOIN Courses_Template C
ON C.ID = SM.CourseID
Group by C.Course,S.Name
Having AVG(SM.Percentage_Obtained) > 80

This sends me back the rows containing the course name, the student’s name, and the amount of percentages above 80%.

This counts for me as “the amounts of students that passed the course”. I would Like to know how to force this query to give me the amount of students who have passed the course in stead of the amount of modules the student has passed and if it is possible

EDIT 1:

STUDENT LAYOUT

CREATE TABLE Students
            (ID INT IDENTITY(1,1) PRIMARY KEY CLUSTERED
            ,StudentNumber VARCHAR(20)
            ,Name VARCHAR(40)
            ,Surname VARCHAR(40)
            ,Student_ID VARCHAR(13)
            ,Languages VARCHAR(200)
            ,[Address] Varchar (512)
            ,Contact_Number varchar(20)
            ,Email Varchar (150)
            ,Days_Absent INT
            ,Student_Web_Username varchar(40)
            ,Student_Web_Password varchar(MAX)
            ,BranchID int 
            ,Constraint FKStudentBranch FOREIGN KEY (BranchID) REFERENCES Branches(ID)
            ,CONSTRAINT Unq_StudentNumber UNIQUE (StudentNumber)
            ,CONSTRAINT Unq_Student_ID UNIQUE (Student_ID)); 

STUDENT_MODULE LAYOUT

CREATE TABLE Student_Modules
            (ID INT IDENTITY(1,1) PRIMARY KEY CLUSTERED
            ,ModuleID INT
            ,StudentID INT
            ,CourseID INT
            ,Percentage_Obtained INT Check (Percentage_Obtained >= -1 AND Percentage_Obtained <= 100)
            ,CONSTRAINT FKStudentModulesChosen FOREIGN KEY (ModuleID) REFERENCES Modules_Template(ID) ON DELETE CASCADE
            ,CONSTRAINT FKStudentModules FOREIGN KEY (StudentID) REFERENCES Students(ID) ON DELETE CASCADE);    

COURSES_TEMPLATE LAYOUT

CREATE TABLE COURSES_TEMPLATE
        (ID INT IDENTITY(1,1) PRIMARY KEY CLUSTERED 
        ,Course VARCHAR(40)
        ,Price SMALLMONEY CHECK(Price > 0)
        ,BranchID INT
        ,CONSTRAINT FKCourseBranches FOREIGN KEY (BranchID) REFERENCES Branches(ID) ON DELETE CASCADE);   
  • 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-26T06:20:54+00:00Added an answer on May 26, 2026 at 6:20 am

    If they need to pass by average 80% across all modules.

    SELECT C.Course, COUNT(*) as [Average] 
    FROM Students S 
    INNER JOIN Student_Modules SM ON S.ID = SM.StudentID 
    INNER JOIN Courses_Template C ON SM.CourseID = C.ID 
    INNER JOIN (
        SELECT SM.StudentID, SM.CourseID 
        FROM Student_Modules SM 
        Group by SM.StudentID, SM.CourseID 
        Having AVG(SM.Percentage_Obtained) > 80
    ) Pass ON SM.StudentID = Pass.StudentID AND SM.CourseID = Pass.CourseID 
    GROUP BY C.Course 
    

    If they need to pass each module by 80% to pass the course then

    SELECT C.Course, COUNT(*) as [Average] 
    FROM Students S 
    INNER JOIN Student_Modules SM ON S.ID = SM.StudentID 
    INNER JOIN Courses_Template C ON SM.CourseID = C.ID 
    LEFT OUTER JOIN (
        SELECT DISTINCT SM.StudentID, SM.CourseID 
        FROM Student_Modules SM 
        WHERE SM.Percentage_Obtained <= 80
    ) as NotPass ON SM.StudentID = NotPass.StudentID AND SM.CourseID = NotPass.CourseID 
    WHERE NotPass.StudentID IS NULL 
    GROUP BY C.Course 
    

    This is untested, let me know any errors or paste incorrect output and expected output.

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

Sidebar

Related Questions

I have been playing around with GTK since a couple of days now,while going
I have been playing around with the postgresql.conf file for a couple days now.
I have been playing around with NSURLConnection. Now I'm trying to grab some data
I have been playing around with jeditable for 2 days now, and it's great!
I have been playing around with Scala parser combinators for some time now, and
I've been playing around with Inno Setup for a couple days now, and have
I have been playing around with some debugging and wrote some C code that
I have been playing around quite a lot with EF4 Code First and I
I have been playing around with jqgrid, and have the following question. To get
I have been playing around with Apple's sample code - UserDefaults - http://developer.apple.com/library/mac/#samplecode/UserDefaults/Introduction/Intro.html -

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.