Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Support DB aggregate by group (new methods) #53679

Open
wants to merge 2 commits into
base: 11.x
Choose a base branch
from

Conversation

GromNaN
Copy link
Contributor

@GromNaN GromNaN commented Nov 27, 2024

Replaces #53209 that have been reverted by #53582.

This new version adds new methods: countByGroup, minByGroup, maxByGroup, sumByGroup and avgByGroup. I did not create the alias averageByGroup, but I can if you believe that's useful.

$sql = 'select ';

if ($query->groups) {
$sql .= $this->columnize($query->groups).', ';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds the group columns in the results, even if they are not used.
If a group column is named aggregate, the DB engine will prefix it with the table name. We don't have conflict with the calculated aggregate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fear this is going to be another breaking change 😅 any way we can be sure?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't affect queries created by the query builder. The result of the aggregate functions count, max... will stay the same (#53581).

It only add fields to the result when calling the grammar method directly. I moved the new columns last to keep the aggregate result first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants