获取 MAX(字段名) 的结果

@param string $field 要统计的字段名
@param bool|string $isMulti 结果集是否为多条 默认只有一条。传字符串时相当于执行了 groupBy($isMulti)
@param bool|string $useMaster 是否使用主库 默认读取从库

@return mixed
176257
public function max($field = 'id', $isMulti = false, $useMaster = false)
    {
        return $this->aggregation($field, $isMulti, $useMaster, 'MAX');
    }
610273
public function count($field = '*', $isMulti = false, $useMaster = false)
    {
        return $this->aggregation($field, $isMulti, $useMaster, 'COUNT');
    }
685553
public function field($field,$except=false){
        if(true === $field) {// 获取全部字段
            $fields     =  $this->getDbFields();
            $field      =  $fields?:'*';
        }elseif($except) {// 字段排除
            if(is_string($field)) {
                $field  =  explode(',',$field);
            }
            $fields     =  $this->getDbFields();
            $field      =  $fields?array_diff($fields,$field):$field;
        }
        $this->options['field']   =   $field;
        return $this;
    }
1199956
public function canMap(Field $field)
    {
        return
            $field->type instanceof FieldType\MultipleStringField ||
            $field->type instanceof FieldType\TextField ||
            $field->type instanceof FieldType\FullTextField;
    }
810666
public static function transform_to_object( &$field ) {
		if ( 1 !== count( $field['value'] ) ) {
			return $field['value'];
		}

		$as_array = ! ( 1 === $field['min'] && 1 === $field['max'] );
		$as_array = apply_filters( Filter::REPEATER_AS_ARRAY, $as_array, $field );

		$field['value'] = $as_array ? $field['value'] : $field['value'][0];
	}
709325
public function values($field)
    {
        $source = $this->getSource();
        if ($pos = strpos($source, '.')) {
            $db = substr($source, 0, $source);
            $collection = substr($source, $pos + 1);
        } else {
            $db = null;
            $collection = $source;
        }

        $mongodb = $this->getConnection();

        $cmd = ['distinct' => $collection, 'key' => $field];
        if ($this->_filters) {
            $filters = [];
            foreach ($this->_filters as $filter) {
                $key = key($filter);
                $value = current($filter);
                if (isset($filters[$key]) || count($filter) !== 1) {
                    $filters = ['$and' => $this->_filters];
                    break;
                }
                $filters[$key] = $value;
            }
            $cmd['query'] = $filters;
        }

        $r = $mongodb->command($cmd, $db)[0];
        if (!$r['ok']) {
            throw new InvalidFormatException([
                '`:distinct` distinct for `:collection` collection failed `:code`: `:msg`',
                'distinct' => $field,
                'code' => $r['code'],
                'msg' => $r['errmsg'],
                'collection' => $source
            ]);
        }

        return $this->_limit ? array_slice($r['values'], $this->_offset, $this->_limit) : $r['values'];
    }
558904
public function count($field = '*')
    {
        if (!empty($this->options['group'])) {
            // 支持GROUP
            $options = $this->getOptions();
            $subSql  = $this->options($options)
                ->field('count(' . $field . ') AS think_count')
                ->bind($this->bind)
                ->buildSql();

            $query = $this->newQuery()->table([$subSql => '_group_count_']);

            if (!empty($options['fetch_sql'])) {
                $query->fetchSql(true);
            }

            $count = $query->aggregate('COUNT', '*');
        } else {
            $count = $this->aggregate('COUNT', $field);
        }

        return is_string($count) ? $count : (int) $count;
    }
137192
public function get(string $field)
    {
        if ($field === "secure")
            return $this->scheme === "https";

        if ($field === "port" && $this->port === null)
        {
            if ($this->scheme === "http") return 80;
            if ($this->scheme === "https") return 443;
            if ($this->scheme === "ftp") return 21;
        }

        if ($field === "suffix")
            return $this->getSuffix();
                
        if ($field === "query")
            return $this->getQuery();

        if (property_exists($this, $field))
            return $this->$field;

        throw new \OutOfRangeException($field);
    }
477961
public function addFieldMax($field, $alias = null)
    {
        $this->addField(new Func('max', $field), $alias); return $this;
    }
519575
public function groupBy($field): IQueryBuilderHandler
    {
        if (($field instanceof Raw) === false) {
            $field = $this->addTablePrefix($field);
        }

        if (\is_array($field) === true) {
            $this->statements['groupBys'] = array_merge($this->statements['groupBys'], $field);
        } else {
            $this->statements['groupBys'][] = $field;
        }

        return $this;
    }
332934
public function count($field = '*')
    {
        $copy = clone $this;

        $copy->_limit = null;
        $copy->_offset = null;
        $copy->_order = null;
        $copy->_aggregate['count'] = ['$sum' => 1];
        $r = $copy->execute();

        return $r ? $r[0]['count'] : 0;
    }
473606
public function getField($field)
    {
        $result = array_filter($this->getFields(), function($input) use ($field) {
            return $field === $input->getName();
        });

        return reset($result);
    }
162107
public function max($field)
    {
        $field = $field instanceof Raw ? $field->toString() : "`{$field}`";
        return $this->select(new Raw("MAX({$field}) as `aggregation`"))->limit(1)->fetch()->aggregation;
    }
1369573
public function max($alias, $field = null, $script = null)
    {
        $aggregation = new MaxAggregation($alias, $field, $script);

        $this->append($aggregation);
    }
626214
protected function _getMultiOptions($field)
    {
        $scaleId = isset($field['scale_id']) ? $field['scale_id'] : 0;
        $qid     = $field['qid'];

        switch ($field['type']) {
            case 'F':
            case 'H':
            case 'L':
            case 'O':
            case 'R':
            case '1':
            case '!':
                $answers = $this->_getHardAnswers($qid, $scaleId);
                break;

            case ':':
                //Get the labels that could apply!
                $answers = false;
                if ($this->_getQuestionAttribute($qid, 'multiflexible_checkbox')) {
                    $answers = $this->_getFixedAnswers($field['type']);
                }
                break;

            case "C":
            case "E":
            case 'G':
            case 'M':
            case 'P':
            case 'Y':
                $answers = $this->_getFixedAnswers($field['type']);
                break;

            default:
                $answers = false;
        }

        return $answers;
    }
159299
public function max(string $field, $value)
    {
        $this->update();
        $this->mongoDbUpdate['$max'][$field] = $value;

        return $this;
    }
1365109
public function merge(/* array($field => $value), ... */)
    {
        $merged = array();

        foreach (func_get_args() as $criteria) {
            if (empty($criteria)) {
                continue;
            }

            $merged['$and'][] = $criteria;
        }

        return (isset($merged['$and']) && count($merged['$and']) === 1)
            ? $merged['$and'][0]
            : $merged;
    }