Skip to content
Advertisement

If null value in a Column A, then how to return the value of column B, and if also B is null, then how to move to the value of C

Have a table in Google Big Query with date, id and store columns where the goal is to keep track how many stores a customer has visited:

I wish to create a SQL query which checks for date in first column (A_date).

  • If it has a date (is not null) then keep the date
  • If it is null then check if the next date column (B_date) has a date and return that
  • If B_date is also null, then check if next date column (C_date) has a date, and return me that date

I wish to end up with a table like this which has a date and id columns along with the store-columns

Advertisement

Answer

Use coalesce:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement