Update docs for any, anyLast, first_value, and last_value

This commit is contained in:
Peter Nguyen 2024-11-16 15:49:35 -08:00
parent 77d288a3e5
commit f9431a3150
4 changed files with 21 additions and 15 deletions

View File

@ -21,7 +21,9 @@ Aliases: `any_value`, [`first_value`](../reference/first_value.md).
**Returned value** **Returned value**
:::note :::note
Supports the `RESPECT NULLS` modifier after the function name. Using this modifier will ensure the function selects the first value passed, regardless of whether it is `NULL` or not. By default, the `anyLast` function never returns `NULL`. However, it supports the `RESPECT NULLS` modifier after the function name. Using this modifier will ensure the function selects the first value passed, regardless of whether it is `NULL` or not.
Alias: `anyRespectNulls`
::: :::
:::note :::note
@ -48,11 +50,11 @@ CREATE TABLE any_nulls (city Nullable(String)) ENGINE=Log;
INSERT INTO any_nulls (city) VALUES (NULL), ('Amsterdam'), ('New York'), ('Tokyo'), ('Valencia'), (NULL); INSERT INTO any_nulls (city) VALUES (NULL), ('Amsterdam'), ('New York'), ('Tokyo'), ('Valencia'), (NULL);
SELECT any(city) FROM any_nulls; SELECT any(city), anyRespectNulls(city) FROM any_nulls;
``` ```
```response ```response
┌─any(city)─┐ ┌─any(city)─┬─anyRespectNulls(city)─
│ Amsterdam │ │ Amsterdam │ ᴺᵁᴸᴸ │
└───────────┘ └───────────┴───────────────────────
``` ```

View File

@ -18,9 +18,9 @@ anyLast(column) [RESPECT NULLS]
:::note :::note
Supports the `RESPECT NULLS` modifier after the function name. Using this modifier will ensure the function selects the last value passed, regardless of whether it is `NULL` or not. By default, the `anyLast` function never returns `NULL`. However, it supports the `RESPECT NULLS `modifier after the function name, which will ensure the function selects the last value passed, regardless of whether it is `NULL` or not.
Alias: `anyLastRepectNulls` Alias: `anyLastRespectNulls`
::: :::
**Returned value** **Returned value**
@ -36,11 +36,11 @@ CREATE TABLE any_last_nulls (city Nullable(String)) ENGINE=Log;
INSERT INTO any_last_nulls (city) VALUES ('Amsterdam'),(NULL),('New York'),('Tokyo'),('Valencia'),(NULL); INSERT INTO any_last_nulls (city) VALUES ('Amsterdam'),(NULL),('New York'),('Tokyo'),('Valencia'),(NULL);
SELECT anyLast(city) FROM any_last_nulls; SELECT anyLast(city), anyLastRespectNulls(city) FROM any_last_nulls;
``` ```
```response ```response
┌─anyLast(city)─┐ ┌─anyLast(city)─┬─anyLastRespectNulls(city)─
│ Valencia │ │ Valencia │ ᴺᵁᴸᴸ │
└───────────────┘ └───────────────┴───────────────────────────
``` ```

View File

@ -15,7 +15,7 @@ first_value (column_name) [[RESPECT NULLS] | [IGNORE NULLS]]
OVER ([[PARTITION BY grouping_column] [ORDER BY sorting_column] OVER ([[PARTITION BY grouping_column] [ORDER BY sorting_column]
[ROWS or RANGE expression_to_bound_rows_withing_the_group]] | [window_name]) [ROWS or RANGE expression_to_bound_rows_withing_the_group]] | [window_name])
FROM table_name FROM table_name
WINDOW window_name as ([[PARTITION BY grouping_column] [ORDER BY sorting_column]) WINDOW window_name as ([PARTITION BY grouping_column] [ORDER BY sorting_column])
``` ```
Alias: `any`. Alias: `any`.
@ -23,6 +23,8 @@ Alias: `any`.
:::note :::note
Using the optional modifier `RESPECT NULLS` after `first_value(column_name)` will ensure that `NULL` arguments are not skipped. Using the optional modifier `RESPECT NULLS` after `first_value(column_name)` will ensure that `NULL` arguments are not skipped.
See [NULL processing](../aggregate-functions/index.md/#null-processing) for more information. See [NULL processing](../aggregate-functions/index.md/#null-processing) for more information.
Alias: `firstValueRespectNulls`
::: :::
For more detail on window function syntax see: [Window Functions - Syntax](./index.md/#syntax). For more detail on window function syntax see: [Window Functions - Syntax](./index.md/#syntax).
@ -48,7 +50,7 @@ CREATE TABLE salaries
) )
Engine = Memory; Engine = Memory;
INSERT INTO salaries FORMAT Values INSERT INTO salaries FORMAT VALUES
('Port Elizabeth Barbarians', 'Gary Chen', 196000, 'F'), ('Port Elizabeth Barbarians', 'Gary Chen', 196000, 'F'),
('New Coreystad Archdukes', 'Charles Juarez', 190000, 'F'), ('New Coreystad Archdukes', 'Charles Juarez', 190000, 'F'),
('Port Elizabeth Barbarians', 'Michael Stanley', 100000, 'D'), ('Port Elizabeth Barbarians', 'Michael Stanley', 100000, 'D'),

View File

@ -23,6 +23,8 @@ Alias: `anyLast`.
:::note :::note
Using the optional modifier `RESPECT NULLS` after `first_value(column_name)` will ensure that `NULL` arguments are not skipped. Using the optional modifier `RESPECT NULLS` after `first_value(column_name)` will ensure that `NULL` arguments are not skipped.
See [NULL processing](../aggregate-functions/index.md/#null-processing) for more information. See [NULL processing](../aggregate-functions/index.md/#null-processing) for more information.
Alias: `lastValueRespectNulls`
::: :::
For more detail on window function syntax see: [Window Functions - Syntax](./index.md/#syntax). For more detail on window function syntax see: [Window Functions - Syntax](./index.md/#syntax).
@ -33,7 +35,7 @@ For more detail on window function syntax see: [Window Functions - Syntax](./ind
**Example** **Example**
In this example the `last_value` function is used to find the highest paid footballer from a fictional dataset of salaries of Premier League football players. In this example the `last_value` function is used to find the lowest paid footballer from a fictional dataset of salaries of Premier League football players.
Query: Query:
@ -48,7 +50,7 @@ CREATE TABLE salaries
) )
Engine = Memory; Engine = Memory;
INSERT INTO salaries FORMAT Values INSERT INTO salaries FORMAT VALUES
('Port Elizabeth Barbarians', 'Gary Chen', 196000, 'F'), ('Port Elizabeth Barbarians', 'Gary Chen', 196000, 'F'),
('New Coreystad Archdukes', 'Charles Juarez', 190000, 'F'), ('New Coreystad Archdukes', 'Charles Juarez', 190000, 'F'),
('Port Elizabeth Barbarians', 'Michael Stanley', 100000, 'D'), ('Port Elizabeth Barbarians', 'Michael Stanley', 100000, 'D'),