Jump to content

Using mysql to determin win or loss


nipster2

Recommended Posts

Hi,

 

I have 2 tables, i know how to join them what im doing is a bit more complex, first table has 2 columns team_id and team_name second table has 4 hometeam_id, awayteam_id, home_score, and away_score is there a select statement where i can determine if a team wins or losses without adding extra colums for who won and who lost, something like:

 

SELECT team_name, COUNT(home_score>away_score) as win FROM scores, teams WHERE hometeam_id=team_id;

 

I though this would show when the home team won but if the home team losses it still shows the home team.

 

hope Im clear and thanks alot in advance

Link to comment
Share on other sites

never mind you guys are too slow i figured it out .... if anyone needs anything like this in the future this is what you do


SELECT team_name, sum((home_score>away_score and hometeam_id=team_id) or (away_score>home_score and awayteam_id=team_id) as wins, sum((home_score>away_score and awayteam_id=team_id) or (away_score>home_score and hometeam_id=team_id) as losses FROM teams, scores ORDER BY team_name;

 

and that should do it, i love it when i slove my own problems, just wish it happened more often lol

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.