last
last, selector
def process last(value: any): any
The selector returns the last value for each group, if the group is not empty. If the group is empty, the default value for the data type is used.
Additionally, this selector requires specifying sort
as an ordering option.
Examples
table T = with
[| as A, as B |]
[| "hello1", "a" |]
[| "hello2", "a" |]
[| "hello3", "b" |]
[| "world1", "b" |]
[| "world2", "c" |]
table G[gdim] = by T.B
where T.B != "c"
show table "" a1b4 with
gdim
last(T.A) sort T.A
group by gdim
The above code results in the following table:
gdim | last(T.A) |
---|---|
a | hello2 |
b | world1 |
c |
(Notice that the value for c
is the empty text value – the default value for text.)
default
can be used to specify the default value to use when the group is empty. For example, last(T.A) sort T.A default "x"
would result in the following table:
gdim | last(T.A) |
---|---|
a | hello2 |
b | world1 |
c | x |