Skip to content

Commit

Permalink
Document NTILE
Browse files Browse the repository at this point in the history
  • Loading branch information
mrotteveel committed May 22, 2021
1 parent 843b20a commit 3f7c0cb
Showing 1 changed file with 90 additions and 35 deletions.
Expand Up @@ -394,11 +394,11 @@ select
----
id salary dense_rank rank row_number sum
-- ------ ---------- ---- ---------- ---
3 8.00 1 1 1 1
4 9.00 2 2 2 2
1 10.00 3 3 3 4
5 10.00 3 3 4 4
2 12.00 4 5 5 5
3 8.00 1 1 1 1
4 9.00 2 2 2 2
1 10.00 3 3 3 4
5 10.00 3 3 4 4
2 12.00 4 5 5 5
----

The difference between `DENSE_RANK` and `RANK` is that there is a gap related to duplicate rows (relative to the window ordering) only in `RANK`.
Expand Down Expand Up @@ -442,12 +442,12 @@ order by salary;
[listing]
----
id salary cume_dist
- ------- ---------
3 8.00 0.2
4 9.00 0.4
1 10.00 0.8
5 10.00 0.8
2 12.00 1
-- ------ ---------
3 8.00 0.2
4 9.00 0.4
1 10.00 0.8
5 10.00 0.8
2 12.00 1
----

.See also <<fblangref40-windowfuncs-rank>>, <<fblangref40-windowfuncs-perc-rank>>
Expand Down Expand Up @@ -488,16 +488,71 @@ order by salary;
[listing]
----
id salary dense_rank
- ------ -----------
3 8.00 1
4 9.00 2
1 10.00 3
5 10.00 3
2 12.00 4
-- ------ ----------
3 8.00 1
4 9.00 2
1 10.00 3
5 10.00 3
2 12.00 4
----

.See also <<fblangref40-windowfuncs-rank>>, <<fblangref40-windowfuncs-row-number>>

[[fblangref40-windowfuncs-ntile]]
=== `NTILE()`

.Available in
DSQL, PSQL

.Result type
`BIGINT`

.Syntax
[listing,subs=+quotes]
----
NTILE ( _number_of_tiles_ ) OVER <window_name_or_spec>
----

[[fblangref40-windowfuncs-tbl-ntile]]
.Arguments of `NTILE`
[cols="<1,<3", options="header",stripes="none"]
|===
^| Argument
^| Description

|number_of_tiles
|Number of tiles (groups).
Restricted to a positive integer literal, a named parameter (PSQL), or a positional parameter (DSQL).
|===

`NTILE` distributes the rows of the current window partition into the specified number of tiles (groups).

[[fblangref40-windowfuncs-ntile-exmpl]]
==== `NTILE` Examples

[source]
----
select
id,
salary,
rank() over (order by salary),
ntile(3) over (order by salary)
from employee
order by salary;
----

.Result
[listing]
----
ID SALARY RANK NTILE
== ====== ==== =====
3 8.00 1 1
4 9.00 2 1
1 10.00 3 2
5 10.00 3 2
2 12.00 5 3
----

[[fblangref40-windowfuncs-perc-rank]]
=== `PERCENT_RANK()`

Expand Down Expand Up @@ -536,12 +591,12 @@ order by salary;
[listing]
----
id salary rank percent_rank
- ------- ---- ------------
3 8.00 1 0
4 9.00 2 0.25
1 10.00 3 0.5
5 10.00 3 0.5
2 12.00 5 1
-- ------ ---- ------------
3 8.00 1 0
4 9.00 2 0.25
1 10.00 3 0.5
5 10.00 3 0.5
2 12.00 5 1
----

.See also <<fblangref40-windowfuncs-rank>>, <<fblangref40-windowfuncs-cume-dist>>
Expand Down Expand Up @@ -582,12 +637,12 @@ order by salary;
[listing]
----
id salary rank
- ------ -----
3 8.00 1
4 9.00 2
1 10.00 3
5 10.00 3
2 12.00 5
-- ------ ----
3 8.00 1
4 9.00 2
1 10.00 3
5 10.00 3
2 12.00 5
----

.See also
Expand Down Expand Up @@ -627,12 +682,12 @@ order by salary;
[listing]
----
id salary rank
- ------ -----
3 8.00 1
4 9.00 2
1 10.00 3
5 10.00 4
2 12.00 5
-- ------ ----
3 8.00 1
4 9.00 2
1 10.00 3
5 10.00 4
2 12.00 5
----

.See also
Expand Down

0 comments on commit 3f7c0cb

Please sign in to comment.