Skip to content

Commit d14822d

Browse files
committed
✨ 新增(Query.php):在Query類別中新增max()和min()方法以計算最大值和最小值
這些變更是為了增強Query類別的功能,使其能夠直接計算指定欄位的最大值和最小值,從而提高查詢的靈活性和便利性。
1 parent 9fe394a commit d14822d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/Query.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,26 @@ public function collect()
133133
return $this->execute();
134134
}
135135

136+
public function max(string $column)
137+
{
138+
$c = clone $this;
139+
$c->columns([
140+
"c" => new Expression("max($column)")
141+
]);
142+
$sql = $c->getSqlString($this->schema->getPlatform());
143+
return $this->schema->query($sql)->fetchColumn(0);
144+
}
145+
146+
public function min(string $column)
147+
{
148+
$c = clone $this;
149+
$c->columns([
150+
"c" => new Expression("min($column)")
151+
]);
152+
$sql = $c->getSqlString($this->schema->getPlatform());
153+
return $this->schema->query($sql)->fetchColumn(0);
154+
}
155+
136156

137157
public function execute(array $input_parameters = [])
138158
{

0 commit comments

Comments
 (0)