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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:27:14+00:00 2026-05-24T19:27:14+00:00

I have a sports tracker MySQL database and am trying to extract some stats;

  • 0

I have a sports tracker MySQL database and am trying to extract some stats; relevant tables are outlined below:

game

id bigint(20) unsigned PK
round_id bigint(20)
team_1_id bigint(20) unsigned
team_2_id bigint(20) unsigned
date datetime

team

id bigint(20) unsigned PK
name varchar(128)

player (not really required for this query)

id bigint(20) unsigned PK
first_name varchar(128)
surname varchar(128)
dob datetime

player_team_game

id bigint(20) unsigned PK
game_id bigint(20) unsigned
player_id bigint(20) unsigned
team_id bigint(20)

stats

id bigint(20) PK
player_team_game_id bigint(20)
kicks int(11)
goals int(11)
tackles int(11)

The intent is to determine total kicks, goals and tackles for each team in each game. An example resultset might look like the following:

game.id    | game.date    | team.name    | stats.kicks    | stats.goals    | stats.tackles  
1          | 2011-01-01   | team1        | 25             | 30             | 35  
1          | 2011-01-01   | team2        | 26             | 31             | 36  
2          | 2011-01-01   | team3        | 27             | 32             | 37  
2          | 2011-01-01   | team4        | 28             | 33             | 38  
3          | 2011-01-02   | team5        | 29             | 34             | 39  
3          | 2011-01-02   | team6        | 30             | 35             | 40  

Can anyone help me with an appropriate query?

Edit: potentially I haven’t made the problem clear; the issue is that the game table has both game.team_id_1 and game.team_id_2 so grouping needs to reflect the results for each team in separate recordsets.

  • 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-24T19:27:16+00:00Added an answer on May 24, 2026 at 7:27 pm

    Try this:

    SELECT
        g.id, g.date,
        t.name,
        SUM(s.kicks),
        SUM(s.goals), 
        SUM(s.tackles)
    FROM stats s
    LEFT JOIN player_team_game ptg ON ptg.id = s.player_team_game_id
    LEFT JOIN game g ON g.id = ptg.game_id
    LEFT JOIN team t ON t.id = ptg.team_id
    GROUP BY ptg.team_id
    ORDER BY g.id, t.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL database that keeps track of sports stats. I'm trying to
I have a MySql database with some sports results in it. I want to
I have a database of sports teams that I am displaying in tables/standings. The
I have this MySQL query. I have database fields with this contents sports,shopping,pool,pc,games shopping,pool,pc,games
I have the following tables: Person, {Id, Name, LastName} Sports, {Id Name, Type} SportsPerPerson,
I have a sports database with a table groupmembers which have the fields ID,
We have 10 years of archived sports data, spread across separate databases. Trying to
We are trying to fetch posts which have 2 keywords (e.g. Chicago Sports) via
In my database I have a willingness field with a value like: sports,pub,drink,drive,smile etc.
I am trying here to basically find users that do have sports & regions

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.