Skip to content
This repository was archived by the owner on Aug 16, 2022. It is now read-only.

Commit 611baa1

Browse files
author
ashwinkumar12345
committed
minor change
1 parent f2a9b2b commit 611baa1

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

docs/sql/window.md

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ A window function performs a calculation across a frame of data rows around the
1111

1212
`PARTITION` and `ORDER` define the frame of data over which the calculations are made.
1313

14-
You can use window functions in following three categories:
14+
You can use window functions in the following three categories:
1515

1616
1. Aggregate Functions: `COUNT()`, `MIN()`, `MAX()`, `AVG()`, and `SUM()`.
1717
2. Ranking Functions: `ROW_NUMBER()`, `RANK()`, `DENSE_RANK()`, `PERCENT_RANK()`, and `NTILE()`.
@@ -28,24 +28,35 @@ function_name (expression [, expression...])
2828
```
2929

3030
The `PARTITION BY` and `ORDER BY` clauses are optional.
31-
{.. note}
31+
{: .note }
3232

33+
To use window functions, enable the new SQL engine:
3334

34-
## Ranking Functions
35+
```json
36+
PUT _cluster/settings
37+
{
38+
"transient": {
39+
"opendistro.sql.engine.new.enabled" : "true"
40+
}
41+
}
42+
```
3543

36-
Ranking functions assign an incremental rank to each row in the frame.
37-
The increase in rank number is based on the ranking function implementation, though the rank is mostly determined by field values in the `ORDER BY` list. If the `PARTITION BY` clause is present, the state of ranking functions (incremental rank number maintained) is reset.
44+
## Ranking functions
3845

39-
If the ranking functions is not used with the window definition that defines the order of data rows, the result is undetermined.
46+
Ranking functions assign an incremental rank to each row in the frame.
4047

41-
In this case, `ROW_NUMBER` assigns row number to data rows in random order. `RANK` and `DENSE_RANK` always assign a rank of 1 to each row.
48+
If the ranking function is not used with the order of the data rows, the result is undetermined.
4249

4350
### ROW_NUMBER
4451

45-
The row number function assigns a row number to each row. As a special case, the row number is always increased by 1 regardless of the fields specified in the `ORDER BY` list.
52+
`ROW_NUMBER` assigns a number to each data row in a random order. As a special case, the row number is always increased by 1 regardless of the fields specified in the `ORDER BY` list.
4653

4754
```sql
48-
od> SELECT gender, balance, ROW_NUMBER() OVER(PARTITION BY gender ORDER BY balance) AS num FROM accounts;
55+
SELECT gender, balance, ROW_NUMBER()
56+
OVER (
57+
PARTITION BY gender ORDER BY balance
58+
)
59+
AS num FROM accounts;
4960
```
5061

5162
| gender | balance | num
@@ -57,10 +68,14 @@ od> SELECT gender, balance, ROW_NUMBER() OVER(PARTITION BY gender ORDER BY balan
5768

5869
### RANK
5970

60-
The `RANK` function assigns a rank to each row. For rows that have the same values for fields specified in the `ORDER BY` list, the same rank is assigned. If this is the case, the next few ranks is skipped depending on the number of ties.
71+
The `RANK` function assigns a rank to each row. For rows that have the same values for fields specified in the `ORDER BY` list, the same rank is assigned. If this is the case, the next few ranks are skipped depending on the number of ties.
6172

6273
```sql
63-
od> SELECT gender, RANK() OVER(ORDER BY gender DESC) AS rnk FROM accounts;
74+
SELECT gender, RANK()
75+
OVER (
76+
ORDER BY gender DESC
77+
)
78+
AS rank FROM accounts;
6479
```
6580

6681
| gender | rank
@@ -75,7 +90,11 @@ od> SELECT gender, RANK() OVER(ORDER BY gender DESC) AS rnk FROM accounts;
7590
Similar to the `RANK` function, `DENSE_RANK` also assigns a rank to each row. The difference is there is no gap between the ranks.
7691

7792
```sql
78-
SELECT gender, DENSE_RANK() OVER(ORDER BY gender DESC) AS rnk FROM accounts;
93+
SELECT gender, DENSE_RANK()
94+
OVER (
95+
ORDER BY gender DESC
96+
)
97+
AS rank FROM accounts;
7998
```
8099

81100
| gender | rank

0 commit comments

Comments
 (0)