List:General Discussion« Previous MessageNext Message »
From:Gabriel PREDA Date:April 10 2006 12:16pm
Subject:Re: Do if and elseif and other calculations
View as plain text  
You can do something like this:

SET @diff = 0;
SELECT count(*) AS number_of_holes, tour_player_score.strokes -
tour_scorecard_hole.par AS overpar, IF(overpar<0,
@diff-(overpar*number_of_holes), ELSEVALUE)
FROM `tour_player_score`, tour_scorecard_hole WHERE tour_player_id=175 AND
tour_scorecard_hole.id=tour_player_score.scorecard_hole_id GROUP BY overpar;

And instead of ELSEVALUE you can insert another IF...
There is also a CASE in MySQL... you can also use that one...

What i don't see here is a DEFAULT value... do you have any ?

--
Gabriel PREDA
Senior Web Developer

Thread
Do if and elseif and other calculationsPeter Lauri10 Apr
  • Re: Do if and elseif and other calculationsBarry10 Apr
    • RE: Do if and elseif and other calculationsPeter Lauri10 Apr
Re: Do if and elseif and other calculationsGabriel PREDA10 Apr
  • RE: Do if and elseif and other calculationsPeter Lauri10 Apr