lundi 7 juin 2021

how to implement multiple if-and function into a sql query?

These two tables below are in the same excel file, but in my database both of them are separated into two different tables.

The first table looks like this:

table1

a_actual      b_actual      c_actual      no
2020-04-21     null         2020-05-23    1
null          2020-04-22    2020-04-27    2

While the second table looks like this:

table2

a        30
b        40
c        100

Both tables are combined and operated with if-and function in excel to get each weight from table 2.

the if function in excel is:

=if(and(a_actual>0; a_actual<=now()); a; (if(and(b_actual>0; b_actual<= now()); b; (if(and(c_actual>0; c_actual<=now());c;0))))

Assuming that the current date is today: 2021-06-08, then the expected result:

no     weight
1       100
2       100

I need to implement this if-and function of excel into a sql query.

I supposed I can use case when, but I don't know exactly how to write the query properly.

How can I implement the if-and function into a sql query?

Thank you very much for any help.

Aucun commentaire:

Enregistrer un commentaire