first
first, selector
def process first(value: any): any
The selector returns the first 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
first(T.A) sort T.A
group by gdim
The above code results in the following table:
gdim | first(T.A) |
---|---|
a | hello1 |
b | hello3 |
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, first(T.A) sort T.A default "x"
would result in the following table:
gdim | first(T.A) |
---|---|
a | hello1 |
b | hello3 |
c | x |