On this page
Class WindowExpression
This represents a SQL window expression used by aggregate and window functions.
Constants
-
string
FOLLOWING'FOLLOWING'
-
string
GROUPS'GROUPS'
-
string
PRECEDING'PRECEDING'
-
string
RANGE'RANGE'
-
string
ROWS'ROWS'
Property Summary
-
$exclusion protected
string|null
-
$frame protected
array|null
-
$name protected
Cake\Database\Expression\IdentifierExpression
-
$order protected
Cake\Database\Expression\OrderByExpression|null
-
$partitions protected
arrayCake\Database\ExpressionInterface>
Method Summary
__clone() public
Clone this object and its subtree of expressions.
__construct() public
buildOffsetSql() protected
Builds frame offset sql.
excludeCurrent() public
Adds current row frame exclusion.
excludeGroup() public
Adds group frame exclusion.
excludeTies() public
Adds ties frame exclusion.
frame() public
Adds a frame to the window.
groups() public
Adds a simple groups frame to the window.
isNamedOnly() public
Return whether is only a named window expression.
name() public
Sets the window name.
order() public
Adds one or more order clauses to the window.
partition() public
Adds one or more partition expressions to the window.
range() public
Adds a simple range frame to the window.
rows() public
Adds a simple rows frame to the window.
sql() public
Converts the Node into a SQL string fragment.
traverse() public
Iterates over each part of the expression recursively for every level of the expressions tree and executes the $callback callable passing as first parameter the instance of the expression currently being iterated.
Method Detail
__clone() public
__clone(): void
Clone this object and its subtree of expressions.
Returns
void
__construct() public
__construct(string $name = '')
Parameters
string
$name optional-
Window name
buildOffsetSql() protected
buildOffsetSql(Cake\Database\ValueBinder $binder, Cake\Database\ExpressionInterface|string|int|null $offset, string $direction): string
Builds frame offset sql.
Parameters
Cake\Database\ValueBinder
$binder-
Value binder
Cake\Database\ExpressionInterface|string|int|null
$offset-
Frame offset
string
$direction-
Frame offset direction
Returns
string
excludeCurrent() public
excludeCurrent(): $this
Adds current row frame exclusion.
Returns
$this
excludeGroup() public
excludeGroup(): $this
Adds group frame exclusion.
Returns
$this
excludeTies() public
excludeTies(): $this
Adds ties frame exclusion.
Returns
$this
frame() public
frame(string $type, Cake\Database\ExpressionInterface|string|int|null $startOffset, string $startDirection, Cake\Database\ExpressionInterface|string|int|null $endOffset, string $endDirection): $this
Adds a frame to the window.
Use the range()
, rows()
or groups()
helpers if you need simple 'BETWEEN offset PRECEDING and offset FOLLOWING' frames.
You can specify any direction for both frame start and frame end.
With both $startOffset
and $endOffset
:
0
- 'CURRENT ROW'null
- 'UNBOUNDED'
Parameters
string
$typeCake\Database\ExpressionInterface|string|int|null
$startOffsetstring
$startDirectionCake\Database\ExpressionInterface|string|int|null
$endOffsetstring
$endDirection
Returns
$this
groups() public
groups(int|null $start, int|null $end = 0): $this
Adds a simple groups frame to the window.
See range()
for details.
Parameters
int|null
$startint|null
$end optional
Returns
$this
isNamedOnly() public
isNamedOnly(): bool
Return whether is only a named window expression.
These window expressions only specify a named window and do not specify their own partitions, frame or order.
Returns
bool
name() public
name(string $name): $this
Sets the window name.
Parameters
string
$name-
Window name
Returns
$this
order() public
order(Cake\Database\ExpressionInterfaceClosure|arrayCake\Database\ExpressionInterface|string>|string $fields): $this
Adds one or more order clauses to the window.
Parameters
Cake\Database\ExpressionInterfaceClosure|arrayCake\Database\ExpressionInterface|string>|string
$fields
Returns
$this
partition() public
partition(Cake\Database\ExpressionInterfaceClosure|arrayCake\Database\ExpressionInterface|string>|string $partitions): $this
Adds one or more partition expressions to the window.
Parameters
Cake\Database\ExpressionInterfaceClosure|arrayCake\Database\ExpressionInterface|string>|string
$partitions
Returns
$this
range() public
range(Cake\Database\ExpressionInterface|string|int|null $start, Cake\Database\ExpressionInterface|string|int|null $end = 0): $this
Adds a simple range frame to the window.
$start
:
0
- 'CURRENT ROW'null
- 'UNBOUNDED PRECEDING'- offset - 'offset PRECEDING'
$end
:
0
- 'CURRENT ROW'null
- 'UNBOUNDED FOLLOWING'- offset - 'offset FOLLOWING'
If you need to use 'FOLLOWING' with frame start or 'PRECEDING' with frame end, use frame()
instead.
Parameters
Cake\Database\ExpressionInterface|string|int|null
$startCake\Database\ExpressionInterface|string|int|null
$end optional
Returns
$this
rows() public
rows(int|null $start, int|null $end = 0): $this
Adds a simple rows frame to the window.
See range()
for details.
Parameters
int|null
$startint|null
$end optional
Returns
$this
sql() public
sql(Cake\Database\ValueBinder $binder): string
Converts the Node into a SQL string fragment.
Parameters
Cake\Database\ValueBinder
$binder
Returns
string
traverse() public
traverse(Closure $callback): $this
Iterates over each part of the expression recursively for every level of the expressions tree and executes the $callback callable passing as first parameter the instance of the expression currently being iterated.
Parameters
Closure
$callback
Returns
$this
Property Detail
$exclusion protected
Type
string|null
$frame protected
Type
array|null
$name protected
Type
Cake\Database\Expression\IdentifierExpression
$order protected
Type
Cake\Database\Expression\OrderByExpression|null
$partitions protected
Type
arrayCake\Database\ExpressionInterface>
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/class-Cake.Database.Expression.WindowExpression.html