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

The Archive Base Latest Questions

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

Here is another problem I have had to deal with in the last couple

  • 0

Here is another problem I have had to deal with in the last couple of days. I have the following query:

SELECT S.Name,S.Surname,S.Student_ID,S.StudentNumber,C.Course, B.Campus_Title,M.Module,SM.Percentage_Obtained,S.Days_Absent
FROM Students S 
INNER JOIN Student_Courses SC
ON SC.StudentID = S.ID 
INNER JOIN Courses_Template C 
ON C.ID = SC.courseID
INNER JOIN Branches B
ON B.ID = S.BranchID 
INNER JOIN Student_Modules SM ON
SM.StudentID =S.ID
INNER JOIN Modules_Template M ON
M.ID = SM.ModuleID

The problem is that I want to rewrite the query to get a calculated result like this:

SELECT S.Name,S.Surname,S.Student_ID,S.StudentNumber,C.Course, B.Campus_Title,M.Module,SM.Percentage_Obtained,S.Days_Absent,
       (SELECT AVG(Percentage_Obtained) 
        FROM Student_Modules 
        INNER JOIN Courses_Template 
        ON Courses_Template.ID = Student_Modules.CourseID
        INNER JOIN Modules_Template 
        ON Courses_Template.ID = Modules_Template.CourseID
        WHERE Modules_Template.Module= M.Module)[AS Class Average]
FROM Students S 
INNER JOIN Student_Courses SC
ON SC.StudentID = S.ID 
INNER JOIN Courses_Template C 
ON C.ID = SC.courseID
INNER JOIN Branches B
ON B.ID = S.BranchID 
INNER JOIN Student_Modules SM ON
SM.StudentID =S.ID
INNER JOIN Modules_Template M ON
M.ID = SM.ModuleID

The Original Values for the modules is (extracted)

M.Modules   AVG(Percentage_Obtained)

Module 1    99
Module 2    98
Module 3    94
Module 1    94
Module 2    22
Module 3    100

The expected Results that I wanted from the second query was this

M.Modules   AVG(Percentage_Obtained) (SubQuery's Average)
Module 1    99                          97  
Module 2    98                          60
Module 3    94                          96
Module 1    94                          97
Module 2    22                          60
Module 3    100                         96

however, what it gave to me was something completely different

The expected Results that I wanted from the second query was this

M.Modules   AVG(Percentage_Obtained) (SubQuery's Average)
Module 1    99                          84  
Module 2    98                          84
Module 3    94                          84
Module 1    94                          84
Module 2    22                          84
Module 3    100                         84

Can anyone perhaps spot my mistake from somewhere? I need all of these fields in a single query, because I must make a report on it. The sub query’s results is crucial

Its almost like I need this (but Dynamically for All recurrences of a Module):

SELECT AVG(Percentage_Obtained) 
FROM Student_Modules 
INNER JOIN Modules_Template ON Modules_Template.ID = Student_Modules.ModuleID 
WHERE Modules_Template.Module = 'Module 1' -- And module 2, and module 3 .... but Dynamically
  • 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-26T04:52:55+00:00Added an answer on May 26, 2026 at 4:52 am

    You can try the following query:

    SELECT S.Name,S.Surname,S.Student_ID,S.StudentNumber,C.Course, B.Campus_Title,M.Module,SM.Percentage_Obtained,S.Days_Absent, SM2.AvgPercentage_Obtained
    FROM Students S 
    INNER JOIN Student_Courses SC
    ON SC.StudentID = S.ID 
    INNER JOIN Courses_Template C 
    ON C.ID = SC.courseID
    INNER JOIN Branches B
    ON B.ID = S.BranchID 
    INNER JOIN Student_Modules SM ON
    SM.StudentID =S.ID
    INNER JOIN Modules_Template M ON
    M.ID = SM.ModuleID
    OUTER APPLY (SELECT AVG(Percentage_Obtained) AvgPercentage_Obtained
                 FROM Student_Modules 
                 INNER JOIN Modules_Template ON Modules_Template.ID = Student_Modules.ModuleID
                 WHERE Student_Modules.Module = M.Module) SM2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After getting a helpful answer here , I have run into yet another problem:
here is the problem. I have one PC using VS2008 (SP1 ) and another
I must be retarded with searching, because here's another seemingly common problem that I
Here's another one for you to help me solve: I have an ASP.NET website
After the you guys helped me out so gracefully last time, here is another
Admittedly, this is a strange problem for me to have, but here is what
I have another problem with ListView :( Now I need to move items in
sorry, I have another problem now. I'm using a new php form method than
I recently had the following memory bug , which is easy to spot here,
I'm here again with another question/problem. I know that topic's title may be like

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.