-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Database count methods #2159
Comments
What about |
That simply returns the number of rows returned, not variance within each grouping. I should have provided results from my two examples above.
In both these scenarios |
Oh! I see what you're saying. And you don't want to build that query manually and just use I'm cool with a |
Well I'm not opposed to using I'll take a look at how the handlers approach |
BaseBuilder.php:194 makes me think that I think I will add a |
I think that's fine for now. |
We don't have any way to perform
count()
calls from the query builder. This is a necessary method for running any grouped queries with multiple returns. Take the nativemigrations
table:If I want to know how many migrations were run in each batch, I'd query
SELECT batch, COUNT(*) FROM migrations GROUP BY batch
. Slightly more complex, if I want to know how many namespaces were part of each batch, I'd querySELECT batch, COUNT(DISTINCT(namespace)) FROM migrations GROUP BY batch
.I run these kind of queries a lot for reporting and summarizing and was surprised to see there is no way to handle this in the query builder. I would propose
selectCount()
andselectCountDistinct()
as additional methods implemented similar toselectMin()
,selectMax()
, andselectAvg()
.I am willing to make an attempt at these but my database experience is heavily weighted in MySQL and I'd want someone with more knowledge of other handlers to collaborate.
The text was updated successfully, but these errors were encountered: