I have a table that looks like this:
| ID | Name | 1_Day_Time | 2_Day_Time |
|---|---|---|---|
| 2B | May | 762 | |
| 8D | Air | 142 | |
| W2 | Tim | 908 | 332 |
| 9H | Bee | ||
| 5E | Ice | 712 |
How do I only select those rows with at least one non-null in the 1_Day_Time and 2_Day_Time columns in kdb/Q?
My intended output is below, with the row of ID 9H removed as there are nulls in both 1_Day_Time and 2_Day_Time columns:
| ID | Name | 1_Day_Time | 2_Day_Time |
|---|---|---|---|
| 2B | May | 762 | |
| 8D | Air | 142 | |
| W2 | Tim | 908 | 332 |
| 5E | Ice | 712 |
>Solution :
i’d advise that you not use column names starting with a number (e.g. prefer "One_Day_Time" over "1_Day_Time"), otherwise you’ll need functional select. But here are a few possible solutions:
q)show t: ([] ID:`2B`8D`W2`9H`5E; Name:`May`Air`Tim`Bee`Ice; One_Day_Time: 762 0N 908 0N 712; Two_Day_Time: 0N 143 332 0N 0N)
ID Name One_Day_Time Two_Day_Time
---------------------------------
2B May 762
8D Air 143
W2 Tim 908 332
9H Bee
5E Ice 712
q)select from t where not null[One_Day_Time] & null[Two_Day_Time]
ID Name One_Day_Time Two_Day_Time
---------------------------------
2B May 762
8D Air 143
W2 Tim 908 332
5E Ice 712
q)select from t where (not null One_Day_Time) | (not null Two_Day_Time)
ID Name One_Day_Time Two_Day_Time
---------------------------------
2B May 762
8D Air 143
W2 Tim 908 332
5E Ice 712
q)select from t where {not all null x} each (One_Day_Time,'Two_Day_Time)
ID Name One_Day_Time Two_Day_Time
---------------------------------
2B May 762
8D Air 143
W2 Tim 908 332
5E Ice 712