I've a simple bigquery table with 3 columns (and some example data) below:
|---------------------|------------------|------------|
| Name | Time | Value |
|---------------------|------------------|------------|
| a | 1 | x |
|---------------------|------------------|------------|
| a | 2 | y |
|---------------------|------------------|------------|
| a | 3 | z |
|---------------------|------------------|------------|
| b | 1 | x |
|---------------------|------------------|------------|
| b | 4 | y |
|---------------------|------------------|------------|
For each name, I'd like to return the value with the max time.
For the above table the 3rd and 5th row should be returned, e.g.,
|---------------------|------------------|------------|
| Name | Time | Value |
|---------------------|------------------|------------|
| a | 3 | z |
|---------------------|------------------|------------|
| b | 4 | y |
|---------------------|------------------|------------|
It is roughly like: (1) first group by Name, (2) find out the max time in each group, (3) identify the row with the max time.
Seems for (1) and (2), we can use group by + max(), but i'm not sure how to achieve the (3) step.
Anyone has ideas of what's the best query I can write to achieve this purpose.
Thanks a lot.