@param array $select
@param array $aggregate

@return array
767606
protected function getAggregateStatement(array $select, array $aggregate): array
    {
        foreach ($aggregate as $func => $value) {
            list($column, $alias) = $value;
            switch ($func) {
                case 'count':
                    $column = sprintf('count(%s)', $column);
                    break;
                case 'max':
                    $column = sprintf('max(%s)', $column);
                    break;
                case 'min':
                    $column = sprintf('min(%s)', $column);
                    break;
                case 'avg':
                    $column = sprintf('avg(%s)', $column);
                    break;
                case 'sum':
                    $column = sprintf('sum(%s)', $column);
                    break;
            }
            $select[$column] = $alias;
        }

        return $select;
    }
16530
protected function loadCount(Select $select) : int
    {
        $limit  = $select->getLimit();
        $offset = $select->getOffset();

        $select->offset(0)->limit(null);

        $rows = $this->connection->load(
            $select->setColumns(['count' => Expr::count()])
        )->asArray();

        if (empty($rows)) {
            return 0;
        }

        $count = (int)$rows[0]['count'] - $offset;

        return $limit !== null ? min($limit, $count) : $count;
    }
1364213
public function select($select, $distinct = FALSE){
        if($distinct){
            $this->select= 'DISTINCT ';
        }else{
            $this->select= '';
        }
        $this->select .= $select;
    }
921469
public function getMessagesByAggregate($aggregateUuid): array
    {
        $messagesByUuid = [];
        /** @var Message $message */
        foreach ($this->messages as $message) {
            if ($message->aggregateUuid === $aggregateUuid) {
                $messagesByUuid[] = $message;
            }
        }

        return $messagesByUuid;
    }
6876
public function aggregate( $function, $columns = ['*'] )
	{
		// Postgres doesn't like ORDER BY when there's no GROUP BY clause
		if ( !isset( $this->groups ) )
			$this->reOrderBy( null );

		$this->aggregate = compact( 'function', 'columns' );

		$previousColumns = $this->columns;

		// We will also back up the select bindings since the select clause will be
		// removed when performing the aggregate function. Once the query is run
		// we will add the bindings back onto this query so they can get used.
		$previousSelectBindings = $this->bindings['select'];

		$this->bindings['select'] = [];

		$results = $this->get( $columns );

		// Once we have executed the query, we will reset the aggregate property so
		// that more select queries can be executed against the database without
		// the aggregate value getting in the way when the grammar builds it.
		$this->aggregate = null;

		$this->columns = $previousColumns;

		$this->bindings['select'] = $previousSelectBindings;

		if ( isset( $results[0] ) )
		{
			$result = array_change_key_case( (array) $results[0] );

			return $result['aggregate'];
		}

		return null;
	}
814004
protected function processSelect(\Zend_Db_Select $select)
    {
        // $select->joinLeft('gems__rounds',      'gto_id_round = gro_id_round', array());
        // $select->join('gems__tracks',          'gto_id_track = gtr_id_track', array());
        $select->join('gems__surveys',         'gto_id_survey = gsu_id_survey', array());
        $select->join('gems__groups',          'gsu_id_primary_group = ggp_id_group', array());
        $select->join('gems__respondents',     'gto_id_respondent = grs_id_user', array());
        $select->join('gems__respondent2org',  '(gto_id_organization = gr2o_id_organization AND gto_id_respondent = gr2o_id_user)', array());
        $select->join('gems__respondent2track','gto_id_respondent_track = gr2t_id_respondent_track', array());        
        $select->join('gems__reception_codes', 'gto_reception_code = grc_id_reception_code', array());
        $select->joinLeft('gems__respondent_relations', '(gto_id_relation = grr_id AND gto_id_respondent = grr_id_respondent)', array()); // Add relation
        $select->joinLeft('gems__track_fields',  '(gto_id_relationfield = gtf_id_field AND gtf_field_type = "relation")', array());       // Add relation fields     
    }
232145
public function selectPdo($select, $param = null)
    {
        $statement = $this->getAdapter()->query($select, ADT::QUERY_MODE_PREPARE);
        $result = $statement->execute($param);

        $resultSet = clone $this->resultSetPrototype;

        return $resultSet->initialize($result);
    }
1321033
public function getChildComponent($select = array())
    {
        $select = $this->_formatSelect($select);
        $select->limit(1);
        $cc = $this->getChildComponents($select);
        if (!$cc) return null;
        return current($cc);
    }
774743
public function select($select = 'ROWID,*')
    {
        //Argument 1 must be a string or array
        Argument::i()->test(1, 'string', 'array');
        
        return \Eden\Sql\Select::i($select);
    }
1019580
public function countAll($select = ['id'])
    {
        $total = $this->db->select($select)->from($this->table)->execute()->rowCount();
        $this->debug->debug(__FUNCTION__, 'Total Result: ' . $total);

        return $total;
    }
64083
protected function createArray(string $fieldName, array $aggregation): array
    {
        $return = [];
        $buckets = $aggregation['buckets'] ?? $aggregation[$fieldName]['buckets'] ?? null;
        if (!$buckets) {
            return $return;
        }
        $attributeId = $this->isAttribute($fieldName);
        foreach ($buckets as $key => $bucket) {
            $return[$key]['count'] = $bucket['doc_count'];
            $return[$key][($attributeId === false ? $fieldName : 'attributeValueId')] = $bucket['key'];
            if ($attributeId !== false) {
                $return[$key]['attributeId'] = $attributeId;
            }
        }

        return array_values($return);
    }
1000960
function select($fields=NULL,$filter=NULL,array $options=NULL,$ttl=0) {
		if (!$options)
			$options=[];
		$options+=[
			'group'=>NULL,
			'order'=>NULL,
			'limit'=>0,
			'offset'=>0
		];
		$tag='';
		if (is_array($ttl))
			list($ttl,$tag)=$ttl;
		$fw=\Base::instance();
		$cache=\Cache::instance();
		if (!($cached=$cache->exists($hash=$fw->hash($this->db->dsn().
			$fw->stringify([$fields,$filter,$options])).($tag?'.'.$tag:'').'.mongo',
			$result)) || !$ttl || $cached[0]+$ttl<microtime(TRUE)) {
			if ($options['group']) {
				$grp=$this->collection->group(
					$options['group']['keys'],
					$options['group']['initial'],
					$options['group']['reduce'],
					[
						'condition'=>$filter,
						'finalize'=>$options['group']['finalize']
					]
				);
				$tmp=$this->db->selectcollection(
					$fw->HOST.'.'.$fw->BASE.'.'.
					uniqid(NULL,TRUE).'.tmp'
				);
				$tmp->batchinsert($grp['retval'],['w'=>1]);
				$filter=[];
				$collection=$tmp;
			}
			else {
				$filter=$filter?:[];
				$collection=$this->collection;
			}
			if ($this->legacy) {
				$this->cursor=$collection->find($filter,$fields?:[]);
				if ($options['order'])
					$this->cursor=$this->cursor->sort($options['order']);
				if ($options['limit'])
					$this->cursor=$this->cursor->limit($options['limit']);
				if ($options['offset'])
					$this->cursor=$this->cursor->skip($options['offset']);
				$result=[];
				while ($this->cursor->hasnext())
					$result[]=$this->cursor->getnext();
			}
			else {
				$this->cursor=$collection->find($filter,[
					'sort'=>$options['order'],
					'limit'=>$options['limit'],
					'skip'=>$options['offset']
				]);
				$result=$this->cursor->toarray();
			}
			if ($options['group'])
				$tmp->drop();
			if ($fw->CACHE && $ttl)
				// Save to cache backend
				$cache->set($hash,$result,$ttl);
		}
		$out=[];
		foreach ($result as $doc)
			$out[]=$this->factory($doc);
		return $out;
	}
1348148
public function setSortOrder(Select $select, $sort)
    {
        if ($sort === '' || null === $sort || empty($sort)) {
            return $select;
        }

        $select->reset('order');

        if (is_string($sort)) {
            $sort = explode(' ', $sort);
        }

        $order = [];

        foreach ($sort as $column) {
            if (strchr($column, '-')) {
                $column = substr($column, 1, strlen($column));
                $direction = Select::ORDER_DESCENDING;
            } else {
                $direction = Select::ORDER_ASCENDING;
            }

            // COLLATE NOCASE
            // fix the sort order to make case insensitive for sqlite database.
            if ('sqlite' == $this->getAdapter()->getPlatform()->getName()) {
                $direction = 'COLLATE NOCASE ' . $direction;
            }

            $order[] = $column . ' ' . $direction;
        }

        return $select->order($order);
    }
1154582
public function modifySelect(\Magento\Framework\DB\Select $select)
    {
        /* aliases for tables ... */
        $tblEntity = 'e'; // this is alias for 'catalog_product_entity' table
        $tblStockItem = $this->_resource->getTableName(self::TBL_STOCK_ITEM);
        $tblWrhsQty = $this->_resource->getTableName(self::TBL_WRHS_QTY);
        /* ... and fields */
        $fldStockItemProdId = StockItem::PRODUCT_ID;
        $fldStockItemId = StockItem::ITEM_ID;
        $fldEntityId = \Magento\Eav\Model\Entity::DEFAULT_ENTITY_ID_FIELD;
        $fldQty = self::FLD_QTY;
        $fldStockItemRef = Quantity::A_STOCK_ITEM_REF;

        /* LEFT JOIN `cataloginventory_stock_item` */
        $on = "`$tblStockItem`.`$fldStockItemProdId`=`$tblEntity`.`$fldEntityId`";
        $fields = [];
        $select->joinLeft($tblStockItem, $on, $fields);

        /* LEFT JOIN `prxgt_wrhs_qty` */
        $on = "`$tblWrhsQty`.`$fldStockItemRef`=`$tblStockItem`.`$fldStockItemId`";
        $fields = [$fldQty => $this->getEquationQty()];
        $select->joinLeft($tblWrhsQty, $on, $fields);

        /* GROUP BY */
        $select->group("$tblEntity.$fldEntityId");
        return $select;
    }
1192471
public function select($select = '*')
    {
        //Argument 1 must be a string or array
        Argument::i()->test(1, 'string', 'array');
        
        //if select is an array
        if (is_array($select)) {
            //transform into a string
            $select = implode(', ', $select);
        }
        
        $this->select = $select;
        
        return $this;
    }
1063439
public function getRow($select)
    {
        if (!is_object($select)) {
            $select = $this->select($select);
        }
        $select->limit(1);
        return $this->getRows($select)->current();
    }
49443
public function serialize(EntityContract $entity, Collection $select = null)
    {
        $bag = parent::serialize($entity, $select);
        $bag->set('url', $entity->getFullUrl());
        $bag->set('media', $entity->media->count() > 0 ? $entity->media[0]->toArray() : null);

        return $bag;
    }