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

Iss 507 support filter clause #617

Merged
merged 3 commits into from
Oct 1, 2022
Merged

Conversation

ahmad-moussawi
Copy link
Contributor

@ahmad-moussawi ahmad-moussawi commented Oct 1, 2022

This PR adds the support for the SelectAggregate method and it's siblings SelectSum, SelectMax, SelectMin, SelectAvg, SelectCount methods, this is better than using SelectRaw.

All these methods accepts an optional filter parameter to filter the aggregated column based on a specified conditions, this will translate to the Aggregation Filter clause on supported compilers like PostgreSQL, and SQLite with a fallback to CASE WHEN statement for the unsupported ones.

Related #507

@ahmad-moussawi ahmad-moussawi merged commit 31ee1e0 into master Oct 1, 2022
@ahmad-moussawi ahmad-moussawi deleted the iss-507_support_filter_clause branch October 1, 2022 06:58
@yankyhgoflow
Copy link
Contributor

👍 Thanks, this is really taking this library to the next level!

Thanks @ahmad-moussawi you rock!

@kenzouno1
Copy link

Missing alias for this feature

@ahmad-moussawi
Copy link
Contributor Author

@kenzouno1 what do you mean exactly by missing alias? is this what you are looking for?

var query = db.Query("Transaction")
                .SelectSum("Amount as Total_2020", q => q.WhereDatePart("year", "date", 2020))
                .SelectSum("Amount as Total_2021", q => q.WhereDatePart("year", "date", 2021))
                .SelectSum("Amount as Total_2022", q => q.WhereDatePart("year", "date", 2022))

check more examples here
https://github.com/sqlkata/querybuilder/blob/master/QueryBuilder.Tests/MySqlExecutionTest.cs#L237

@kenzouno1
Copy link

That's exactly what I'm looking for. Thank you

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.

3 participants