From 72b6c3ccaa1fc36d5f71732f4082ad3c75956deb Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 22 Oct 2018 14:15:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=9A=E5=90=88=E6=9F=A5=E8=AF=A2=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E6=94=AF=E6=8C=81DISTINCT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index ba4eff84..30a17466 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -558,11 +558,15 @@ class Query */ public function aggregate($aggregate, $field, $force = false) { + if (0 === stripos($field, 'DISTINCT ')) { + list($distinct, $field) = explode(' ', $field); + } + if (!preg_match('/^[\w\.\*]+$/', $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; }