Add mean() method to Query Builder
Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
parent
ff3c757543
commit
f2b3871b21
4 changed files with 74 additions and 3 deletions
29
src/Functions/Mean.php
Normal file
29
src/Functions/Mean.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Arendsen\FluxQueryBuilder\Type\ArrayType;
|
||||
|
||||
class Mean extends Base
|
||||
{
|
||||
/**
|
||||
* @var string $column
|
||||
*/
|
||||
private $column;
|
||||
|
||||
public function __construct(string $column = '_value')
|
||||
{
|
||||
$this->column = $column;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$input = new ArrayType(array_filter([
|
||||
'column' => !empty($this->column) && $this->column !== '_value' ?
|
||||
new Type($this->column) : null
|
||||
]));
|
||||
|
||||
return '|> mean(' . $input . ') ';
|
||||
}
|
||||
}
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue