# give/4.16.9/src/Framework/QueryBuilder/Concerns/GroupByStatement.php

GiveWP – Donation Plugin and Fundraising Platform, version 4.16.9. 37 lines.

- Page: https://pluginprobe.com/plugins/give/4.16.9/code/src/Framework/QueryBuilder/Concerns/GroupByStatement.php
- Raw: https://pluginprobe.com/plugins/give/4.16.9/raw/src/Framework/QueryBuilder/Concerns/GroupByStatement.php
- Modified: 2022-03-31T22:56:06+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/give/4.16.9/code/src/Framework/QueryBuilder/Concerns/GroupByStatement.php#L10-L20`.

```php
<?php

namespace Give\Framework\QueryBuilder\Concerns;

use Give\Framework\Database\DB;

/**
 * @since 2.19.0
 */
trait GroupByStatement
{

    /**
     * @var string
     */
    protected $groupByColumns = [];

    /**
     * @return $this
     */
    public function groupBy($tableColumn)
    {
        if (!in_array($tableColumn, $this->groupByColumns, true)) {
            $this->groupByColumns[] = DB::prepare('%1s', $tableColumn);
        }

        return $this;
    }

    protected function getGroupBySQL()
    {
        return !empty($this->groupByColumns)
            ? ['GROUP BY ' . implode(',', $this->groupByColumns)]
            : [];
    }
}

```
