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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:50:15+00:00 2026-05-26T23:50:15+00:00

The following query is giving me differing results on different rows and it should

  • 0

The following query is giving me differing results on different rows and it should be giving me the same result on all rows.

Here is the query:

select * from 
    (SELECT mjla_db.StudentRecordTable2.studentId, 
            mjla_db.StudentTable2.lastName as `Last Name`, 
            mjla_db.StudentTable2.firstName as `First Name`, 
            sum(if(quizId=60,quizGrade,0)) as `Quiz 60`, 
            sum(if(quizId=64,quizGrade,0)) as `Quiz 64`, 
            sum(if(quizId=71,quizGrade,0)) as `Quiz 71`,
            (sum(quizGrade*(1-abs(sign(quizId-60)))) + 
                sum(quizGrade*(1-abs(sign(quizId-64)))) + 
                sum(quizGrade*(1-abs(sign(quizId-71)))) )/3 
                as Averages 
    FROM mjla_db.StudentRecordTable2, mjla_db.StudentTable2 
    where (mjla_db.StudentRecordTable2.studentId=mjla_db.StudentTable2.studentId) 
    GROUP BY studentId) as A 
where A.studentId 
in (select mjla_db.ClassStudentTable2.studentId 
    from mjla_db.ClassStudentTable2 
    where mjla_db.ClassStudentTable2.classId='CS3071F2011');

The number of quizzes are dynamic, number of students are dynamic.


Here is the contents of the table where mjla_db.StudentRecordTable2.classId='CS3071F2011'.

+-------------+-----------+-----------+--------+
| classId     | studentId | quizGrade | quizId |
+-------------+-----------+-----------+--------+
| CS3071F2011 | A1        |      NULL |     60 |
| CS3071F2011 | A2        |      NULL |     60 |
| CS3071F2011 | A5        |      NULL |     60 |
| CS3071F2011 | A1        |      NULL |     64 |
| CS3071F2011 | A2        |      NULL |     64 |
| CS3071F2011 | A5        |      NULL |     64 |
| CS3071F2011 | A7        |      NULL |     64 |
| CS3071F2011 | A3        |      NULL |     64 |
| CS3071F2011 | A4        |      NULL |     64 |
| CS3071F2011 | A3        |      NULL |     60 |
| CS3071F2011 | A4        |      NULL |     60 |
| CS3071F2011 | A7        |      NULL |     60 |
| CS3071F2011 | A1        |      NULL |     71 |
| CS3071F2011 | A2        |      NULL |     71 |
| CS3071F2011 | A5        |      NULL |     71 |
| CS3071F2011 | A7        |      NULL |     71 |
| CS3071F2011 | A3        |      NULL |     71 |
| CS3071F2011 | A4        |      NULL |     71 |
+-------------+-----------+-----------+--------+

Here is the result of the query.

+-----------+-----------+------------+---------+---------+---------+----------+
| studentId | Last Name | First Name | Quiz 60 | Quiz 64 | Quiz 71 | Averages |
+-----------+-----------+------------+---------+---------+---------+----------+
| A1        | harry     | thomas     |       0 |       0 |       0 |   0.0000 |
| A2        | harry     | willy      |       0 |       0 |       0 |   0.0000 |
| A3        | billy     | gregory    |       0 |       0 |       0 |   0.0000 |
| A4        | goat      | bobb       |       0 |       0 |       0 |   0.0000 |
| A5        | nogood    | tom        |       0 |       0 |       0 |     NULL |
| A7        | foobar    | dick       |       0 |       0 |       0 |     NULL |
+-----------+-----------+------------+---------+---------+---------+----------+

The expected result of the query would be for all the averages to be 0.0000, why are the last two varying?

Also, whenever i do the query so that i only get one student at a time A5 and A7 still show up as NULL and the rest show up fine…


A solution to this problem or an alternate query to achieve the same goal would be acceptable. My goal is to get a table that each row is a representation of each student in the class and their grades on all the quizzes and an average of all the quizzes that student.

  • 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-26T23:50:15+00:00Added an answer on May 26, 2026 at 11:50 pm

    All of your quizGrade values are NULL, which you’re using in math calculations ((sum(quizGrade*(1-abs(sign(quizId-60)))). As soon as a db NULL enters into pretty much any kind of operation, the whole operation becomes null. The question shouldn’t be why the last two are null, but why the first four AREN’T.

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

Sidebar

Related Questions

I have written the select fallowing query but it is giving different results surprisingly
The following query returns strange results for me: SELECT `Statistics`.`StatisticID`, COUNT(`Votes`.`StatisticID`) AS `Score`, COUNT(`Views`.`StatisticID`)
The following query: SELECT DISTINCT ClassName FROM SiteTree ORDER BY ClassName is returning things
I have the following LINQ query: List<FileInputItem> inputList = GetInputList(); var results = from
I have the following query: SELECT m.*, COUNT(c.chapter_nr) as chapters, MAX(c.chapter_nr) as latest_chapter FROM
I have the following query: SELECT o.ClientId, o.MAX(Date), o.OrderNumber FROM dbo.tblOrders GROUP BY o.ClientId,
I have the following query: SELECT FROM tblMailToSend WHERE (DateToSend < @dateToSend OR DateToSend
I have written the following query: SELECT CLIENT.CLIENTNO, CLIENT.CNAME, TOTALS.TOTAL FROM CLIENT, (SELECT CLIENTNO,
The following query will display all Dewey Decimal numbers that have been duplicated in
I have following query written in HQL for Hibernate. ======================================================================== select new map(ret.retailerDesc as

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.