Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a function to get the max of two values in Google BigQuery?

Tags:

I want to get the maximum value of 2 Integer (or 2 float).

I know I can do it with a IF function like this: IF (column1 > column2, column1, column2)

however I was wondering if a function to do that exists or if there is a plan to add that kind of function in the future.

In MySQL there is the GREATER function that can do that. Example: GREATER(column1, column2).

like image 437
YABADABADOU Avatar asked Sep 27 '13 14:09

YABADABADOU


People also ask

How do you use Max in BigQuery?

MAX DescriptionReturns the maximum value of non- NULL expressions. Returns NULL if there are zero input rows or expression evaluates to NULL for all rows. Returns NaN if the input contains a NaN .

How do you compare two strings in BigQuery?

Comparing strings To do that we can use one of the STRING comparison functions: STARTS_WITH(value1, value2)-> Returns True/False if value1 starts with the substring value2.

What does Array_agg do in BigQuery?

ARRAY_AGG. Returns an ARRAY of expression values. To learn more about the optional arguments in this function and how to use them, see Aggregate function calls.

What is coalesce in BigQuery?

COALESCE(expr[, ... ]) Description. Returns the value of the first non-null expression. The remaining expressions are not evaluated.


1 Answers

BigQuery supports

GREATEST(expr1, expr2, ...)  

which returns the largest argument. I've filed an internal bug to get this added to our public documentation.

like image 171
Jason Roselander Avatar answered Sep 24 '22 18:09

Jason Roselander