I have a table like this
ID | Type | Val0 | Val1
1  |  0   |  A   | NULL
2  |  1   | NULL |  B
I need to select Val0 when the type is 0, and Val1 when the type is 1, and ValN when type is N...
How can I do that?
You can extract a column of pandas DataFrame based on another value by using the DataFrame. query() method. The query() is used to query the columns of a DataFrame with a boolean expression.
To select columns, choose one of the following options: Type SELECT , followed by the names of the columns in the order that you want them to appear on the report. Use commas to separate the column names.
SELECT CASE
          WHEN Type = 0 THEN Val0
          WHEN Type = 1 Then Val1
          .
          .
          WHEN Type = N Then ValN
       END 
  FROM tbl
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With