Skip to content

Commit

Permalink
✨ 新增(Query.php):在Query類別中新增max()和min()方法以計算最大值和最小值
Browse files Browse the repository at this point in the history
這些變更是為了增強Query類別的功能,使其能夠直接計算指定欄位的最大值和最小值,從而提高查詢的靈活性和便利性。
  • Loading branch information
mathsgod committed Sep 20, 2024
1 parent 9fe394a commit d14822d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,26 @@ public function collect()
return $this->execute();
}

public function max(string $column)
{
$c = clone $this;
$c->columns([
"c" => new Expression("max($column)")
]);
$sql = $c->getSqlString($this->schema->getPlatform());
return $this->schema->query($sql)->fetchColumn(0);
}

public function min(string $column)
{
$c = clone $this;
$c->columns([
"c" => new Expression("min($column)")
]);
$sql = $c->getSqlString($this->schema->getPlatform());
return $this->schema->query($sql)->fetchColumn(0);
}


public function execute(array $input_parameters = [])
{
Expand Down

0 comments on commit d14822d

Please sign in to comment.