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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:14:35+00:00 2026-05-25T20:14:35+00:00

Struggling to do this with one query: scores ========== | child_name | week |

  • 0

Struggling to do this with one query:

scores
==========

| child_name | week | behaviour_score | test | test_score |
+---------------------------------------------------------+
| jo         | 1    | 75              | 1    | 55         |
| jo         | 1    | 75              | 2    | 54         |
| jo         | 2    | 71              | 1    | 65         |
| jo         | 3    | 68              | 1    | 70         |
| jo         | 3    | 68              | 2    | 74         |
| jo         | 3    | 68              | 3    | 45         |

Each child takes 1 to n tests each week. Behaviour is recorded as a value for the week, but is stored in each row – so e.g. jo’s behaviour for week 1 is 75, and for week 3 is 68. It’s not normalised. I know. Wasn’t my call.

The table contains records like this for many children.

I am trying to return 1 row per child, with name, sum of behaviour, and sum of test scores.
But because behaviour isnt normalised it must only count the value once per week.

So sum of behaviour above is 75+71+68
And sum of test scores is 55+54+65+70+74+45

My first attempt was

SELECT 
    child_name, 
    SUM(behaviour_score), 
    SUM(test_Score) 
FROM results 
GROUP BY child_name

But of course, that gives too large a value for behaviour score as it doesnt account for the values being duplicated for a given week.

Is it possible to achieve this with one query?

  • 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-25T20:14:35+00:00Added an answer on May 25, 2026 at 8:14 pm

    You need to first reduce the data into one row per child, per week with the total test score but only one (let’s take the MAX) behavior score), then base your query on that:

    SELECT 
       child_name, 
       SUM(behaviour_score), 
       SUM(test_Score) 
    FROM (
          SELECT child_name, MAX(behavior_score), SUM(test_Score)
          FROM result GROUP BY child_name, week
         ) AS OnePerWeek
    GROUP BY child_name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been struggling with this one SQL query requirement today that I was wondering
I've been struggling with this one for a couple of days now. My current
Hey, I'm really struggling with this one. I'am trying to port a small piece
I am struggling a bit to figure this one out. I'm working on an
I've been struggling for a while with this one; I'll try to explain it
OK, struggling to get a definitive answer to this one... I have an application
This is a bit of a strange one, but I've been struggling for a
I hope I'm explaining this well. I'm struggling with this query: I have this
I've been struggling with this query for a few days now. I'm using PHP/MySQL.
Quite new to Linq, and I'm struggling with this one. Basically I have a

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.