Skip to content

Commit bd2c791

Browse files
💬Generate LLM translations (#968)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Quan <[email protected]>
1 parent 2524356 commit bd2c791

File tree

3 files changed

+266
-157
lines changed

3 files changed

+266
-157
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,92 @@
11
---
2-
title: FIRST_VALUE
3-
---
4-
5-
import FunctionDescription from '@site/src/components/FunctionDescription';
6-
7-
<FunctionDescription description="Introduced: v1.1.50"/>
8-
9-
Returns the first value from an ordered group of values.
10-
11-
See also:
12-
13-
- [LAST_VALUE](last-value.md)
14-
- [NTH_VALUE](nth-value.md)
15-
16-
## Syntax
17-
18-
```sql
19-
FIRST_VALUE(expression) OVER ([PARTITION BY partition_expression] ORDER BY order_expression [window_frame])
20-
```
21-
22-
For the syntax of window frame, see [Window Frame Syntax](index.md#window-frame-syntax).
23-
24-
## Examples
25-
26-
```sql
27-
CREATE TABLE employees (
28-
employee_id INT,
29-
first_name VARCHAR(50),
30-
last_name VARCHAR(50),
31-
salary DECIMAL(10,2)
32-
);
33-
34-
INSERT INTO employees (employee_id, first_name, last_name, salary)
35-
VALUES
36-
(1, 'John', 'Doe', 5000.00),
37-
(2, 'Jane', 'Smith', 6000.00),
38-
(3, 'David', 'Johnson', 5500.00),
39-
(4, 'Mary', 'Williams', 7000.00),
40-
(5, 'Michael', 'Brown', 4500.00);
41-
42-
-- Use FIRST_VALUE to retrieve the first name of the employee with the highest salary
43-
SELECT employee_id, first_name, last_name, salary,
44-
FIRST_VALUE(first_name) OVER (ORDER BY salary DESC) AS highest_salary_first_name
45-
FROM employees;
46-
47-
48-
employee_id | first_name | last_name | salary | highest_salary_first_name
49-
------------+------------+-----------+---------+--------------------------
50-
4 | Mary | Williams | 7000.00 | Mary
51-
2 | Jane | Smith | 6000.00 | Mary
52-
3 | David | Johnson | 5500.00 | Mary
53-
1 | John | Doe | 5000.00 | Mary
54-
5 | Michael | Brown | 4500.00 | Mary
2+
title: FIRST_VALUE
3+
---
4+
5+
import FunctionDescription from '@site/src/components/FunctionDescription';
6+
7+
<FunctionDescription description="引入版本: v1.2.568"/>
8+
9+
当使用 `IGNORE NULLS` 时,FIRST_VALUE 函数返回窗口框架中第一个非 NULL 的值(如果所有值均为 NULL,则返回 NULL)。如果未指定,默认行为是 `RESPECT NULLS`
10+
11+
另请参阅:
12+
13+
- [LAST_VALUE](last-value.md)
14+
- [NTH_VALUE](nth-value.md)
15+
16+
## 语法
17+
18+
```sql
19+
FIRST_VALUE(expression) [ { IGNORE | RESPECT } NULLS ] OVER ([PARTITION BY partition_expression] ORDER BY order_expression [window_frame])
20+
```
21+
22+
有关窗口框架的语法,请参阅 [窗口框架语法](index.md#window-frame-syntax)
23+
24+
## 示例
25+
26+
```sql
27+
CREATE TABLE employees (
28+
employee_id INT,
29+
first_name VARCHAR(50),
30+
last_name VARCHAR(50),
31+
salary DECIMAL(10,2)
32+
);
33+
34+
INSERT INTO employees (employee_id, first_name, last_name, salary)
35+
VALUES
36+
(1, 'John', 'Doe', 5000.00),
37+
(2, 'Jane', 'Smith', 6000.00),
38+
(3, 'David', 'Johnson', 5500.00),
39+
(4, 'Mary', 'Williams', 7000.00),
40+
(5, 'Michael', 'Brown', 4500.00);
41+
42+
-- 使用 FIRST_VALUE 获取薪水最高的员工的姓名
43+
SELECT employee_id, first_name, last_name, salary,
44+
FIRST_VALUE(first_name) OVER (ORDER BY salary DESC) AS highest_salary_first_name
45+
FROM employees;
46+
47+
48+
employee_id | first_name | last_name | salary | highest_salary_first_name
49+
------------+------------+-----------+---------+--------------------------
50+
4 | Mary | Williams | 7000.00 | Mary
51+
2 | Jane | Smith | 6000.00 | Mary
52+
3 | David | Johnson | 5500.00 | Mary
53+
1 | John | Doe | 5000.00 | Mary
54+
5 | Michael | Brown | 4500.00 | Mary
55+
56+
```
57+
58+
### 使用 IGNORE NULLS 返回非 NULL 值
59+
60+
```sql
61+
CREATE or replace TABLE example AS SELECT * FROM (VALUES
62+
(0, 1, 614),
63+
(1, 1, null),
64+
(2, 1, null),
65+
(3, 1, 639),
66+
(4, 1, 2027)
67+
) tbl(id, user_id, order_id);
68+
69+
70+
SELECT
71+
id,
72+
user_id,
73+
order_id,
74+
FIRST_VALUE (order_id) IGNORE nulls over (
75+
PARTITION BY user_id
76+
ORDER BY
77+
id ROWS BETWEEN 1 PRECEDING AND UNBOUNDED FOLLOWING
78+
) AS last_order_id
79+
FROM
80+
example
81+
82+
┌───────────────────────────────────────────────────────┐
83+
│ id │ user_id │ order_id │ last_order_id │
84+
├───────┼─────────┼──────────────────┼──────────────────┤
85+
01614614
86+
11NULL614
87+
21NULL639
88+
31639639
89+
412027639
90+
└───────────────────────────────────────────────────────┘
91+
5592
```
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,90 @@
11
---
2-
title: LAST_VALUE
3-
---
4-
5-
import FunctionDescription from '@site/src/components/FunctionDescription';
6-
7-
<FunctionDescription description="Introduced: v1.1.50"/>
8-
9-
Returns the last value from an ordered group of values.
10-
11-
See also:
12-
13-
- [FIRST_VALUE](first-value.md)
14-
- [NTH_VALUE](nth-value.md)
15-
16-
## Syntax
17-
18-
```sql
19-
LAST_VALUE(expression) OVER ([PARTITION BY partition_expression] ORDER BY order_expression [window_frame])
20-
```
21-
22-
For the syntax of window frame, see [Window Frame Syntax](index.md#window-frame-syntax).
23-
24-
## Examples
25-
26-
```sql
27-
CREATE TABLE employees (
28-
employee_id INT,
29-
first_name VARCHAR(50),
30-
last_name VARCHAR(50),
31-
salary DECIMAL(10,2)
32-
);
33-
34-
INSERT INTO employees (employee_id, first_name, last_name, salary)
35-
VALUES
36-
(1, 'John', 'Doe', 5000.00),
37-
(2, 'Jane', 'Smith', 6000.00),
38-
(3, 'David', 'Johnson', 5500.00),
39-
(4, 'Mary', 'Williams', 7000.00),
40-
(5, 'Michael', 'Brown', 4500.00);
41-
42-
-- Use LAST_VALUE to retrieve the first name of the employee with the lowest salary
43-
SELECT employee_id, first_name, last_name, salary,
44-
LAST_VALUE(first_name) OVER (ORDER BY salary DESC) AS lowest_salary_first_name
45-
FROM employees;
46-
47-
employee_id | first_name | last_name | salary | lowest_salary_first_name
48-
------------+------------+-----------+---------+------------------------
49-
4 | Mary | Williams | 7000.00 | Michael
50-
2 | Jane | Smith | 6000.00 | Michael
51-
3 | David | Johnson | 5500.00 | Michael
52-
1 | John | Doe | 5000.00 | Michael
53-
5 | Michael | Brown | 4500.00 | Michael
2+
title: LAST_VALUE
3+
---
4+
5+
import FunctionDescription from '@site/src/components/FunctionDescription';
6+
7+
<FunctionDescription description="引入版本: v1.2.568"/>
8+
9+
当使用 `IGNORE NULLS` 时,LAST_VALUE 函数返回窗口框架中最后一个非 NULL 值(如果所有值均为 NULL,则返回 NULL)。如果未指定,默认值为 RESPECT NULLS。
10+
11+
另请参阅:
12+
13+
- [FIRST_VALUE](first-value.md)
14+
- [NTH_VALUE](nth-value.md)
15+
16+
## 语法
17+
18+
```sql
19+
LAST_VALUE(expression) [ { IGNORE | RESPECT } NULLS ] OVER ([PARTITION BY partition_expression] ORDER BY order_expression [window_frame])
20+
```
21+
22+
有关窗口框架的语法,请参阅 [窗口框架语法](index.md#window-frame-syntax)
23+
24+
## 示例
25+
26+
```sql
27+
CREATE TABLE employees (
28+
employee_id INT,
29+
first_name VARCHAR(50),
30+
last_name VARCHAR(50),
31+
salary DECIMAL(10,2)
32+
);
33+
34+
INSERT INTO employees (employee_id, first_name, last_name, salary)
35+
VALUES
36+
(1, 'John', 'Doe', 5000.00),
37+
(2, 'Jane', 'Smith', 6000.00),
38+
(3, 'David', 'Johnson', 5500.00),
39+
(4, 'Mary', 'Williams', 7000.00),
40+
(5, 'Michael', 'Brown', 4500.00);
41+
42+
-- 使用 LAST_VALUE 检索薪水最低的员工的 first_name
43+
SELECT employee_id, first_name, last_name, salary,
44+
LAST_VALUE(first_name) OVER (ORDER BY salary DESC) AS lowest_salary_first_name
45+
FROM employees;
46+
47+
employee_id | first_name | last_name | salary | lowest_salary_first_name
48+
------------+------------+-----------+---------+------------------------
49+
4 | Mary | Williams | 7000.00 | Michael
50+
2 | Jane | Smith | 6000.00 | Michael
51+
3 | David | Johnson | 5500.00 | Michael
52+
1 | John | Doe | 5000.00 | Michael
53+
5 | Michael | Brown | 4500.00 | Michael
54+
```
55+
56+
### 使用 IGNORE NULLS 返回非 NULL 值
57+
58+
```sql
59+
CREATE or replace TABLE example AS SELECT * FROM (VALUES
60+
(0, 1, 614),
61+
(1, 1, null),
62+
(2, 1, null),
63+
(3, 1, 639),
64+
(4, 1, 2027)
65+
) tbl(id, user_id, order_id);
66+
67+
68+
SELECT
69+
id,
70+
user_id,
71+
order_id,
72+
LAST_VALUE (order_id) IGNORE NULLS over (
73+
PARTITION BY user_id
74+
ORDER BY
75+
id ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING
76+
) AS last_order_id
77+
FROM
78+
example
79+
80+
┌───────────────────────────────────────────────────────┐
81+
│ id │ user_id │ order_id │ last_order_id │
82+
├───────┼─────────┼──────────────────┼──────────────────┤
83+
01614NULL
84+
11NULL614
85+
21NULL614
86+
31639614
87+
412027639
88+
└───────────────────────────────────────────────────────┘
89+
5490
```

0 commit comments

Comments
 (0)