Subject Re: [firebird-support] The greater/lesser of a number of values
Author Kjell Rilbe
ai_no_kareshi wrote:

> Does Firebird provide functions for determining the greater/lesser of
> two or more values?
>
> For instance, I have a table that stores three ratings per candidate.
> What I want is to calculate, for each record, the difference between
> the largest of the three ratings and the smallest of the three ratings.
>
> Suppose there were functions like these and they were called MAX_VAL
> and MIN_VAL, my query would look something like this:
>
> 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.

Maybe you can join the table with itself once for each rating in a
correlated subquery and use the aggregates min/max?

Kjell
--
--------------------------------------
Kjell Rilbe
DataDIA AB
E-post: kjell@...
Telefon: 08-761 06 55
Mobil: 0733-44 24 64