Jump to content

a single table complex query


heraldic2

Recommended Posts

I manage a fantasy football league.

I have a table in a database that contains a record of every game played over 6 years of the league.

What I would like to do is create a query that I can use to display on a website by php.

I would like to use a drop down list that contains the names of the teams, then when the submit button is pushed the query will take the team name that was chosen and show that teams win / lose record vs. all other teams in the league.

 

Example output:

Green Bay Packers

Team Name

Wins

Losses

Chicago Bears

4

2

Dallas Cowboys

2

12

and so on . . .

In this example the Green Bay Packers have beaten the Chicago Bears 4 of the 6 times they have played and the Packers have lost 2 of the 6 times they have played.

 

I am unsure how to approach this situation as my design of the table has left me with a problem. 

I can compute a teams home wins / losses OR I can compute a teams away wins / losses, but not both at the same time.

 

I use a 1 in the 'home_team_win' column if the home team won.  If the home team lost then they get a 1 in the `home_team_loss`column.  Same holds true for the away team.

 

I just don't know how to get a query that will show me the wins / losses added up over the years for every team that the selected team has played against.

 

Any help with this query would be much appreciated.

 

The table

TABLE `games` (
`games_id` INT(20) NOT NULL AUTO_INCREMENT,
`week` VARCHAR(7) NULL DEFAULT NULL,
`year` YEAR(4) NULL DEFAULT '2011',
`home_owner_id` INT(2) NULL DEFAULT NULL,
`home_team` VARCHAR(50) NULL DEFAULT NULL,
`home_team_score` FLOAT(6,1) NULL DEFAULT NULL,
`home_team_win` INT(1) NULL DEFAULT '0' COMMENT '1 = game winner',
`home_team_loss` INT(1) NULL DEFAULT '0' COMMENT '1 = game loser',
`away_owner_id` INT(2) NULL DEFAULT NULL,
`away_team` VARCHAR(50) NULL DEFAULT NULL,
`away_team_score` FLOAT(6,1) NULL DEFAULT NULL,
`away_team_win` INT(1) NULL DEFAULT '0' COMMENT '1 = game winner',
`away_team_loss` INT(1) NULL DEFAULT '0' COMMENT '1 = game loser',
`playoff_game` INT(1) NULL DEFAULT '0' COMMENT 'Was this game a playoff game? 1 = yes 0 = no',
`superbowl` INT(1) NULL DEFAULT '0' COMMENT 'Was this game a super bowl 1 = yes 0 = no',

 

Thank you very much for your time.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.