Skip to content

Commit fd24b0a

Browse files
authored
Add examples for LAG (#8082)
1 parent 0cac18a commit fd24b0a

File tree

2 files changed

+51
-0
lines changed
  • ydb/docs
    • en/core/yql/reference/yql-core/builtins/_includes/window
    • ru/core/yql/reference/yql-core/builtins/_includes/window

2 files changed

+51
-0
lines changed

ydb/docs/en/core/yql/reference/yql-core/builtins/_includes/window/lag_lead.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,28 @@ FROM my_table
1818
WINDOW w AS (ORDER BY key);
1919
```
2020

21+
```yql
22+
SELECT item, odd, LAG(item, 1) OVER w as lag1 FROM (
23+
SELECT item, item % 2 as odd FROM (
24+
SELECT AsList(1, 2, 3, 4, 5, 6, 7) as item
25+
)
26+
FLATTEN BY item
27+
)
28+
WINDOW w As (
29+
PARTITION BY odd
30+
ORDER BY item
31+
);
32+
33+
/* Output:
34+
item odd lag1
35+
--------------------
36+
2 0 NULL
37+
4 0 2
38+
6 0 4
39+
1 1 NULL
40+
3 1 1
41+
5 1 3
42+
7 1 5
43+
*/
44+
45+
```

ydb/docs/ru/core/yql/reference/yql-core/builtins/_includes/window/lag_lead.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,29 @@ SELECT
1515
FROM my_table
1616
WINDOW w AS (ORDER BY key);
1717
```
18+
19+
```yql
20+
SELECT item, odd, LAG(item, 1) OVER w as lag1 FROM (
21+
SELECT item, item % 2 as odd FROM (
22+
SELECT AsList(1, 2, 3, 4, 5, 6, 7) as item
23+
)
24+
FLATTEN BY item
25+
)
26+
WINDOW w As (
27+
PARTITION BY odd
28+
ORDER BY item
29+
);
30+
31+
/* Output:
32+
item odd lag1
33+
--------------------
34+
2 0 NULL
35+
4 0 2
36+
6 0 4
37+
1 1 NULL
38+
3 1 1
39+
5 1 3
40+
7 1 5
41+
*/
42+
43+
```

0 commit comments

Comments
 (0)