franco pina
franco pina

Reputation: 333

Max date in colmuns Bigquery

I am trying to get the last date between 3 columns (for each row) I found a solution in SQL server but apparently it can't be used in Bigquery

enter image description here

SELECT 
   ID, 
   (SELECT MAX(LastUpdateDate)
      FROM (VALUES (UpdateByApp1Date),(UpdateByApp2Date),(UpdateByApp3Date)) AS UpdateDate(LastUpdateDate)) 
   AS LastUpdateDate
FROM ##TestTable

Upvotes: 0

Views: 2381

Answers (1)

Mikhail Berlyant
Mikhail Berlyant

Reputation: 172993

Consider below approach

select id, name, 
  greatest(UpdateByApp1Date, UpdateByApp2Date, UpdateByApp3Date) as LastUpdateDate
from TestTable

Upvotes: 3

Related Questions