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

  • Home
  • SEARCH
  • 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 6013937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:37:12+00:00 2026-05-23T02:37:12+00:00

The following code should return me the average numbers the first five players did

  • 0

The following code should return me the average numbers the first five players did in a game.

SELECT "Starting 5" as Flag, 
       count(gs.ID) as Games, 
       avg(s.min) as Min, 
       avg(s.P2M) as P2M, 
       avg(s.P2A) as P2A, 
       100*avg(s.P2M/s.P2A) as P2P,  
       avg(s.P3M) as P3M,  
       avg(s.P3A) as P3A,  
       100*avg(s.P3M/s.P3A) as P3P,  
       avg(s.FTM) as FTM,  
       avg(s.FTA) as FTA,  
       100*avg(s.FTM/s.FTA) as FTP,  
       avg(s.OFFENSE) as OFFENSE,  
       avg(s.DEF) as DEF,  
       avg(s.TOT) as TOT,  
       avg(s.AST) as AST,  
       avg(s.TO) as 'TO',  
       avg(s.ST) as ST,  
       avg(s.FV) as FV,  
       avg(s.CM) as CM,  
       avg(s.PTS) as PTS,  
       avg(s.P2M - s.P2A + s.P3M - s.P3A + s.FTM - s.FTA + s.TOT + s.AST + s.ST + s.FV + s.PTS - s.TO - s.CM) as EFF  
FROM gamesstats AS gs 
    INNER JOIN gamesstatsplayers as gp ON gs.id=gp.GameStatID 
    INNER JOIN players as p ON gp.PlayerID = p.ID 
    INNER JOIN stats as s ON gp.stat=s.id 
                         WHERE gs.HomeTeamID ='664' 
                         and gs.HomeScore > gs.VisitorScore 
                         and gp.IsHomePlayer = 1 
                         AND gp.IsFirst5 = 1 
                         AND gs.SeasonStart = '2010' 
                         AND gs.LeagueID = '145' 

I should get 4 games and the averages in each. What I get is the avg of each player in a game. That means I get 20 games and 1/5 of the average I want in each. The problem is for some reason it makes a cartesian product instead of join. Was tryign to find the bug for several hours but can’t seem to find it.

The table explanations:

gamesstats is for holding each game.

gamesstatsplayers is has a connection to a game via GameStatID and is responsible for each player stats in each game.

players is a table of all players there are.

stats is a table with just the stats, gamesstats has a link to stats to give you the stats of a whole team in a game(2 links, one for home and one for visitor), gamesstatsplayers has a link to stats to give you the stats of 1 player in 1 game. (That means stats is for two things).

  • 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-23T02:37:13+00:00Added an answer on May 23, 2026 at 2:37 am

    without knowing the schema, this is a guess, but you probably need to group on the GameStatID, if that is the primary key for the game.

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

Sidebar

Related Questions

I have the following code and it should return just one value (id) from
The following code should find the appropriate project tag and remove it from the
In this thread some one commented that the following code should only be used
I am pretty sure the following button-activated form code should raise a Control-F12 in
Following is some obviously-defective code for which I think the compiler should emit a
Using the following code: $credits.getCredits = function() { return $(this).find( 'tbody' ).children( 'tr' ).map(function(){
One question regarding whether the following code should yield a compiler warning or not
The following code should copy data from an wifstream to wcout. After the content
Following code, when compiled and run with g++, prints '1' twice, whereas I expect
The following code works great in IE, but not in FF or Safari. I

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.