mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
聚合查询字段支持DISTINCT
This commit is contained in:
@@ -558,11 +558,15 @@ class Query
|
|||||||
*/
|
*/
|
||||||
public function aggregate($aggregate, $field, $force = false)
|
public function aggregate($aggregate, $field, $force = false)
|
||||||
{
|
{
|
||||||
|
if (0 === stripos($field, 'DISTINCT ')) {
|
||||||
|
list($distinct, $field) = explode(' ', $field);
|
||||||
|
}
|
||||||
|
|
||||||
if (!preg_match('/^[\w\.\*]+$/', $field)) {
|
if (!preg_match('/^[\w\.\*]+$/', $field)) {
|
||||||
throw new Exception('not support data:' . $field);
|
throw new Exception('not support data:' . $field);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->value($aggregate . '(' . $field . ') AS tp_' . strtolower($aggregate), 0, $force);
|
$result = $this->value($aggregate . '(' . (!empty($distinct) ? 'DISTINCT ' : '') . $field . ') AS tp_' . strtolower($aggregate), 0, $force);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user