Subject Re: [firebird-support] The greater/lesser of a number of values
Author Ivan Prenosil
> SELECT MAX_VAL(Rating1, Rating2, Rating3) - MIN_VAL(Rating1, Rating2,
> Rating3) AS RatingDiff
> FROM Candidate
>
> If there aren't any functions like these, I would appreciate it if
> someone could suggest a different approach to solving this problem.

SELECT
CASE WHEN Rating1>Rating2 AND Rating1>Rating3 THEN Rating1 WHEN Rating2>Rating3 THEN Rating2 ELSE Rating3 END -
CASE WHEN Rating1<Rating2 AND Rating1<Rating3 THEN Rating1 WHEN Rating2<Rating3 THEN Rating2 ELSE Rating3 END as RatingDiff
FROM Candidate

Ivan
http://www.volny.cz/iprenosil/interbase/