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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:27:32+00:00 2026-05-20T01:27:32+00:00

I’ve been puzzling over how to structure a special query, and the best I

  • 0

I’ve been puzzling over how to structure a special query, and the best I can figure out is that it would have to be some kind of complex subquery system.

I’m not entirely sure, though.

I have three tables, teams, matches, and scored.

The teams table contains a list of team numbers and corresponding team names.

The matches table contains a list recorded match results (one row per team per match), with the corresponding team number.

The scored table contains a list of all of the information about each score the team made, and the corresponding match result id.

┌────────────┐
| TEAMS      |
├────────────┤
│ teamnumber |
│ teamname   |
└────────────┘

┌───────────────┐
| MATCHES       |
├───────────────┤
│ teamnumber    |
│ matchresultid |
└───────────────┘

┌───────────────┐
| SCORED        |
├───────────────┤
│ matchscoredid |
│ matchresultid |
└───────────────┘

Given a teamnumber, I need to get the average number of rows in scored per matchresultid. How would I do that?

  • 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-20T01:27:33+00:00Added an answer on May 20, 2026 at 1:27 am

    I think the one element you left out that may have confused others is the actual score of the game a given team was playing against. So basically you want one team, and through the course of the season, you want the average # points they scored…

    select 
          t.teamnumber,
          t.teamname,
          avg( s.totalpoints ) TeamAvgPoints
       from 
          teams t
             join matches m
                on t.teamnumber = m.teamnumber
                join scored s
                   on m.matchresultid = s.matchresultid
       where 
          t.teamnumber = SomeValue
    

    If you want a comparison of ALL teams averages, ignore the WHERE clause and just do a group by…

       group by
          t.teamnumber, 
          t.teamname
    

    If the scored table has multiple rows per game, then a pre-aggregate would need to be done per game to have total points first, THEN get the average… something like

    select
          PreQuery.TeamNumber,
          PreQuery.TeamName,
          avg( ifnull( PreQuery.MatchTotalPoints, 0 ) ) AvgPerGame
       from 
          ( select 
                t.teamnumber,
                t.teamname,
                m.matchresultid,
                count(*) MatchTotalPoints
             from 
                teams t
                   left join matches m
                      on t.teamnumber = m.teamnumber
                      left join scored s
                         on m.matchresultid = s.matchresultid
             where 
                t.teamnumber IN( SomeValue, AnotherValue, MoreValues, EtcValue )
             group by
                t.teamnumber,
                t.teamname,
                m.matchresultid ) PreQuery
       group by 
           PreQuery.TeamNumber,
           PreQuery.TeamName
    

    In THIS version of the query, if you wanted to compare all teams, remove the inner WHERE clause for a specific team, and apply the group by to the OUTER query by teamnumber and teamname.

    To get your extra qualifier for the entire list, I’ve changed to LEFT joins, and finished with an IFNULL() for the average…

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.