Sample Header Ad - 728x90

For each tuple, get the name of the first column which is non-zero

1 vote
1 answer
308 views
I have a table in Hive which looks like:
| Name | 1990 | 1991 | 1992 | 1993 | 1994 |
| Rex  | 0    | 0    | 1    | 1    | 1    |
| Max  | 0    | 0    | 0    | 0    | 1    |
| Phil | 1    | 1    | 1    | 1    | 1    |
I would like to get, for each row, the name of the first column which is non-zero, so something like:
| Name | Column |
| Rex  | 1992   |
| Max  | 1994   |
| Phil | 1990   |
For each row, it is guaranteed that: * There is at least one column with "1"; and * If column X has is "1", for each column Y > X, column Y will also have a "1".
Asked by user2891462 (113 rep)
Nov 28, 2021, 04:47 PM
Last activity: Dec 1, 2021, 05:21 PM