Skip to content
Advertisement

How to join two tables by dependent match keys in BigQuery?

I have two tables in BigQuery First one is a list of rates. Rates have default values with source equal -1 for each combo code - offer. Apart from combo code - offer, some rates have specified source

Second table has same columns as first table except rates + any other data.

My goal join rates by matched code - offer - source otherwise use default rate by matched code - offer with source equal -1

In example query returns default rates only:

Next query returns rates with specified source and null when source did not match

How can I join rates correct?

Advertisement

Answer

You can left join twice and use conditional logic:

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