If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > forumulae calculation in mysql

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-19-04, 10:10
jimmy2bob jimmy2bob is offline
Registered User
 
Join Date: Feb 2004
Posts: 7
forumulae calculation in mysql

is it possible to have a colum that calculates something?

what i'm wanting to do is calculate if the team has won drawn or lost. I know how do do this in excel,

if team A is at home then
{If homescore > awayscor = W
if awayscore < homescore = L
else D
}
if team A is away then....

Home Team Score Away Team Score Outcome
Team 1 2 Team 12 1 ?
Team 3 1 Team 5 1 ?

etc...

hope anyone can help

jamie
Reply With Quote
  #2 (permalink)  
Old 02-19-04, 10:28
ursus ursus is offline
Registered User
 
Join Date: Feb 2004
Location: Erehwon
Posts: 18
Re: forumulae calculation in mysql

You need a CASE statement.
http://www.mysql.com/doc/en/CASE_Statement.html

[code]
select home_team, home_score, away_team, away_score,
case
when home_score>away_score then 'W'
when home_score<away_score then 'L'
else 'D'
end as outcome
from ......
[\code]

Quote:
Originally posted by jimmy2bob
is it possible to have a colum that calculates something?

what i'm wanting to do is calculate if the team has won drawn or lost. I know how do do this in excel,

if team A is at home then
{If homescore > awayscor = W
if awayscore < homescore = L
else D
}
if team A is away then....

Home Team Score Away Team Score Outcome
Team 1 2 Team 12 1 ?
Team 3 1 Team 5 1 ?

etc...

hope anyone can help

jamie
Reply With Quote
  #3 (permalink)  
Old 02-19-04, 10:34
jimmy2bob jimmy2bob is offline
Registered User
 
Join Date: Feb 2004
Posts: 7
Re: forumulae calculation in mysql

where does this get added?
Reply With Quote
  #4 (permalink)  
Old 02-19-04, 10:43
ursus ursus is offline
Registered User
 
Join Date: Feb 2004
Location: Erehwon
Posts: 18
the case statment goes into the Select statement you're using to retrieve your records
Reply With Quote
  #5 (permalink)  
Old 02-19-04, 11:39
smithhayward smithhayward is offline
Registered User
 
Join Date: Apr 2003
Location: Edison, NJ / Oakland, NJ (Work)
Posts: 32
Wouldn't you want to have a W/L/D listed for each team. The win/loss/draw isn't assigned to the game, it's assigned to the teams who played.

Team 1: (W) 13 - Team 23: (L) 8

something like that huh?
__________________
-----------------------------------
Smith Hayward
-----------------------------------
Reply With Quote
  #6 (permalink)  
Old 02-19-04, 12:02
ursus ursus is offline
Registered User
 
Join Date: Feb 2004
Location: Erehwon
Posts: 18
Good point. Tracking W/L/D at a team level would certainly make calculating team standings easier. Maybe three tables then:

Team
-team_id (primary)
-team_name

Game
-game_id (primary)
-home_team
-away_team

Score
-team_id (foreign)
-game_id (foreign)
-score
-outcome
Reply With Quote
  #7 (permalink)  
Old 03-11-04, 05:45
jimmy2bob jimmy2bob is offline
Registered User
 
Join Date: Feb 2004
Posts: 7
i dont need the table calculating as i've already done that.. and calculated the home and away tables..

What i'm wanting is the form for the last 6 games a team has played.

I have selected the games, limited to the last six and now I want to know if the team has w, d or l a game.

It will eventually look like;

Form (Last 6) WWWDDL.

hope this makes sense...
Reply With Quote
  #8 (permalink)  
Old 03-11-04, 06:31
jimmy2bob jimmy2bob is offline
Registered User
 
Join Date: Feb 2004
Posts: 7
its alright, fixed it!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On