Let's say I have a table like this:
name | score_a | score_b
-----+---------+--------
Joe | 100 | 24
Sam | 96 | 438
Bob | 76 | 101
... | ... | ...
I'd like to select the minimum of score_a and score_b. In other words, something like:
SELECT name, MIN(score_a, score_b)
FROM table
The results, of course, would be:
name | min
-----+-----
Joe | 24
Sam | 96
Bob | 76
... | ...
However, when I try this in Postgres, I get, "No function matches the given name and argument types. You may need to add explicit type casts." MAX() and MIN() appear to work across rows rather than columns.
Is it possible to do what I'm attempting?
MAX()
of two values, it'sGREATEST(a, b)
:) – Wenoa