vendredi 27 mars 2020

If statement Big Query

I'm quite new user of big query with basic SQL skills. I would like to build a query that is using a conditional IF statement to add a new value in one of my field

Here is the data that i have

    YEAR  |  MONTH   | NEW YEAR
----------+----------+-------------
     2018 | April    | 
     2019 | June     | 
     2020 | May      | 

I was thinking about the following request :

Select
IF (YEAR ="2018" AND MONTH=April) THEN (NEW YEAR =2019),
IF (YEAR ="2019" AND MONTH=June) THEN (NEW YEAR =2020),
IF (YEAR ="2020" AND MONTH=May) THEN (NEW YEAR =2021)
FROM 'database'
WHERE source ='name source'

i'm trying to figure out, but impossible to set the right syntax and logic

Many thanks for your help Much appreciated !

Aucun commentaire:

Enregistrer un commentaire