Retrieve the "count" result of the query.

@param string $columns

@return int
546208
public function count($columns = null)
    {
        $this->compileWheres();
        $result = $this->query->count();

        return (int) $result;
    }
670181
public function getCountForPagination($columns = ['*'])
    {
        $this->backupFieldsForCount();

        $this->aggregate = ['function' => 'count', 'columns' => $this->clearSelectAliases($columns)];

        $results = $this->get();

        $this->aggregate = null;

        $this->restoreFieldsForCount();
        if (isset($this->groups)) {
            return count($results);
        }

        if (! isset($results[0])) {
            return 0;
        }

        $item = $results[0];

        if (is_object($item)) {
            return (int) $item->aggregate;
        }

        return (int) array_change_key_case((array) $item)['aggregate'];
    }
1032260
public function count($where = null)
  {
    $m = $this->getManager();

    $q = $m->getQueryBuilder()
      ->select($this->getTable())
      ->columns('COUNT(*) as total')
      ->where($where);

    return $m->query($q)->fetchColumn();
  }
1092732
public function getFresh($columns = array('*'))
	{
		// If no columns have been specified for the select statement, we will set them
		// here to either the passed columns, or the standard default of retrieving
		// all of the columns on the table using the "wildcard" column character.
		if (is_null($this->columns))
		{
			$this->columns = $columns;
		}

		// Drop all columns if * is present, MongoDB does not work this way
		if (in_array('*', $this->columns))
		{
			$this->columns = array();
		}

		// Compile wheres
		$wheres = $this->compileWheres();

		// Aggregation query.
		if (isset($this->aggregate['function']))
		{
			switch ($this->aggregate['function'])
			{
				case 'count':
					$result = $this->collection->group(array(
						'key' => array('_id' => true),
						'initial' => array('count' => 0),
						'reduce' => "function(doc,out){ out.count++;}",
						'condition' => $wheres,

					));

					$result = count($result);
					break;

				case 'max':
				case 'min':
					$result = $this->collection->query(array(
						'query' => $wheres,
						'fields' => $this->columns,
						'sort' => array($this->columns[0] => $this->aggregate['function'] === 'max' ? -1 : 1),
						'limit' => 1,
					));
					$result = empty($result) ? 0 : $result[0][$this->columns[0]];
					break;

				default:
					$result = array();
					break;
			}

			return array(
				array(
					'aggregate' => $result,
				),
			);
		}
		// Normal query
		else
		{
			// Execute query.
			return $this->collection->query(array(
				'query' => $wheres,
				'fields' => $this->columns,
				'sort' => $this->orders,
				'skip' => $this->offset,
				'limit' => $this->limit,
			));
		}
	}
375987
public function countResults(string $table): int
    {
        $queryBuilder = $this->conn->createQueryBuilder();
        $rows = $queryBuilder->select('COUNT(1)')->from($table)->execute();

        return (int) $rows->fetch(\Doctrine\DBAL\FetchMode::NUMERIC)[0];
    }
36823
public function select($columns = [])
    {
        $expr = new ColumnExpression($this->getSQLStatement());

        if ($columns instanceof Closure) {
            $columns($expr);
        } else {
            if (!is_array($columns)) {
                $columns = [$columns];
            }
            $expr->columns($columns);
        }
    }
907821
public function get($columns = ['*'])
    {
        $original = $this->columns;

        if (is_null($original)) {
            $this->columns = $columns;
        }

        $results = $this->runSelect();

        $this->columns = $original;

        return $results;
    }
1191906
public function get($columns = ['*'])
    {
        $columns = $this->query->getQuery()->columns ? [] : $columns;

        if ($columns === ['*']) {
            $columns = [$this->related->getTable().'.*'];
        }

        $columns[] = $this->getQualifiedFirstLocalKeyName().' as '.static::THROUGH_KEY;

        $this->query->addSelect($columns);

        return $this->query->get();
    }
414791
protected function select($columns=[])
    {
        $query = $this->model->newQuery()->getQuery();
        if ($columns) {
            $query->select($columns);
        }
        return $query;
    }
908660
protected function runPaginationCountQuery($columns = ['*'])
    {
        if ($this->havings) {
            $query = $this->cloneWithout(['orders', 'limit', 'offset'])
                          ->cloneWithoutBindings(['order']);

            // We don't need simple columns, only specials
            // like subselects which is why we're using
            // havings after all.
            foreach ($query->columns as $key => $value) {
                if (is_string($value)) {
                    unset($query->columns[$key]);
                }
            }

            $countQuery = DB::table(DB::raw('('.$query->toSql().') as x'))->mergeBindings($query);

            // Using a aggregate here won't work when
            // groups are present because the
            // getCountForPagination() is
            // checking for it.
            if (!$this->groups) {
                $countQuery->setAggregate('count', $this->withoutSelectAliases($columns));
            }

            return $countQuery->get()->all();
        }

        return $this->cloneWithout(['columns', 'orders', 'limit', 'offset'])
                    ->cloneWithoutBindings(['select', 'order'])
                    ->setAggregate('count', $this->withoutSelectAliases($columns))
                    ->get()->all();
    }
1075019
public function sum(string $column): int
    {
        $sum = $this->queryRelate->getQuery()->sum($column);

        $this->resetQueryRelate();

        return $sum;
    }
322053
public function countAll($column = '*')
    {
        $results = $this->db->get($this->table, NULL, $column);

        return (int) count($results);
    }
598670
public function count($column = '*', bool $distinct = false)
    {
        parent::count($column, $distinct);
        return $this->getColumnResult();
    }
835651
public function count() {
		if ($this->count === null) {
			$groupPart = $this->select->getPart(Select::GROUP);
			
			$select = empty($groupPart)
				? $this->prepareSelect(clone $this->select)
				: $this->prepareSubquerySelect(clone $this->select);
			
			$this->count = (int) $select->query(PDO::FETCH_OBJ)->fetch()->{self::COUNT_COLUMN};
		}
		
		return $this->count;
	}
264890
private function getCount($column)
    {
        $alias = 'count';

        // Save initial state
        $original = clone $this->queryBuilder;
        $bindings = $this->bindings;

        // Set guessed query and execute it
        $this->queryBuilder->setQueryString($this->queryBuilder->guessCountQuery($column, $alias));
        $count = $this->query($alias);

        // And finally restore initial state
        $this->queryBuilder = $original;
        $this->bindings = $bindings;

        return $count;
    }
1278597
public function calc($column)
    {
        $builder = clone $this;
        $builder->columns($column);

        $query = $builder->getQuery();
        $resultset = $query->execute();

        return $resultset->getFirst();
    }
1285513
public function avg($column): int
    {
        $avg = $this->queryRelate->getQuery()->avg($column);

        $this->resetQueryRelate();

        return $avg;
    }