mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-09 16:12:49 +08:00
改进count查询对group的支持
This commit is contained in:
@@ -509,10 +509,17 @@ class Query
|
||||
* COUNT查询
|
||||
* @access public
|
||||
* @param string $field 字段名
|
||||
* @return integer
|
||||
* @return integer|string
|
||||
*/
|
||||
public function count($field = '*')
|
||||
{
|
||||
if (isset($this->options['group'])) {
|
||||
// 支持GROUP
|
||||
$options = $this->getOptions();
|
||||
$subSql = $this->options($options)->field('count(' . $field . ')')->bind($this->bind)->buildSql();
|
||||
return $this->table([$subSql => '_group_count_'])->value('COUNT(*) AS tp_count', 0, true);
|
||||
}
|
||||
|
||||
return $this->value('COUNT(' . $field . ') AS tp_count', 0, true);
|
||||
}
|
||||
|
||||
@@ -2227,7 +2234,7 @@ class Query
|
||||
if ($data instanceof Query) {
|
||||
return $data->select();
|
||||
} elseif ($data instanceof \Closure) {
|
||||
call_user_func_array($data, [& $this]);
|
||||
call_user_func_array($data, [ & $this]);
|
||||
$data = null;
|
||||
}
|
||||
// 分析查询表达式
|
||||
@@ -2327,7 +2334,7 @@ class Query
|
||||
if ($data instanceof Query) {
|
||||
return $data->find();
|
||||
} elseif ($data instanceof \Closure) {
|
||||
call_user_func_array($data, [& $this]);
|
||||
call_user_func_array($data, [ & $this]);
|
||||
$data = null;
|
||||
}
|
||||
// 分析查询表达式
|
||||
|
||||
Reference in New Issue
Block a user