Drupal Grupal gives us alternatives:
If you haven’t already heard, SQL 2022 has introduced a new built-in system function called GREATEST. Simply put, it is to a set of columns, variables, expressions etc. what the
MAXfunction is to a set of values (i.e., rows) of a single column or expression. The opposite ofGREATESTfunction isLEASTfunction which returns the smallest value from the supplied list of columns, variables, constants etc.GREATEST&LEASTcan be considered a pair, just asMIN/MAXfunctions are.
In other situations, GREATEST() and LEAST() are known as ARGMAX() and ARGMIN(), respectively.
Drupal shows us two alternatives to the built-in function and includes a performance comparison.