Query: GroupBy with Where produces invalid SQL #10870
Closed
Comments
@smitpatel Of course, thats pretty much the SQL EF6 did generate (for MSSQL, but works for SQLite as well). SELECT
[GroupBy1].[K1] AS [Size]
FROM ( SELECT
[Extent1].[Size] AS [K1],
COUNT(1) AS [A1]
FROM [dbo].[FileEntries] AS [Extent1]
GROUP BY [Extent1].[Size]
) AS [GroupBy1]
WHERE [GroupBy1].[A1] > 1 |
It seems like almost all relational providers have Having clause supported in SelectExpression. We will try to translate to Having clause instead of causing a subquery (like EF6). |
smitpatel
added a commit
that referenced
this issue
Mar 13, 2018
- Add support for translating OrderBy after GroupBy operator - Add support for `HAVING` clause in SQL which would be generated when translating predicate after GroupByAggregate Resolves #10870 - Make sure client eval warning is not issued when translating GroupByAggregate Resolves #11157 - GroupBy Aggregate works when key/element/result selector is DTO instead of anonymous type Resolves #11176 - Make sure that SQL added to GROUP BY clause is not aliased Resolves #11218 Part of #10012
smitpatel
added a commit
that referenced
this issue
Mar 14, 2018
- Add support for translating OrderBy after GroupBy operator - Add support for `HAVING` clause in SQL which would be generated when translating predicate after GroupByAggregate Resolves #10870 - Make sure client eval warning is not issued when translating GroupByAggregate Resolves #11157 - GroupBy Aggregate works when key/element/result selector is DTO instead of anonymous type Resolves #11176 - Make sure that SQL added to GROUP BY clause is not aliased Resolves #11218 - Translate GroupBy Constant/Parameter with aggregates Resolves #9969 Part of #10012
smitpatel
added a commit
that referenced
this issue
Mar 14, 2018
- Add support for translating OrderBy after GroupBy operator - Add support for `HAVING` clause in SQL which would be generated when translating predicate after GroupByAggregate Resolves #10870 - Make sure client eval warning is not issued when translating GroupByAggregate Resolves #11157 - GroupBy Aggregate works when element/result selector is DTO instead of anonymous type Resolves #11176 (KeySelector has to be client evaluated) - Make sure that SQL added to GROUP BY clause is not aliased Resolves #11218 - Translate GroupBy Constant/Parameter with aggregates Resolves #9969 Part of #10012 Part of #2341
smitpatel
added a commit
that referenced
this issue
Mar 14, 2018
- Add support for translating OrderBy after GroupBy operator - Add support for `HAVING` clause in SQL which would be generated when translating predicate after GroupByAggregate Resolves #10870 - Make sure client eval warning is not issued when translating GroupByAggregate Resolves #11157 - GroupBy Aggregate works when element/result selector is DTO instead of anonymous type Resolves #11176 (KeySelector has to be client evaluated) - Make sure that SQL added to GROUP BY clause is not aliased Resolves #11218 - Translate GroupBy Constant/Parameter with aggregates Resolves #9969 Part of #10012 Part of #2341
smitpatel
added a commit
that referenced
this issue
Mar 14, 2018
- Add support for translating OrderBy after GroupBy operator - Add support for `HAVING` clause in SQL which would be generated when translating predicate after GroupByAggregate Resolves #10870 - Make sure client eval warning is not issued when translating GroupByAggregate Resolves #11157 - GroupBy Aggregate works when element/result selector is DTO instead of anonymous type Resolves #11176 (KeySelector has to be client evaluated) - Make sure that SQL added to GROUP BY clause is not aliased Resolves #11218 - Translate GroupBy Constant/Parameter with aggregates Resolves #9969 Part of #10012 Part of #2341
We generate SQL like this now SELECT [o].[CustomerID] AS [Key], COUNT(*) AS [Count]
FROM [Orders] AS [o]
GROUP BY [o].[CustomerID]
HAVING COUNT(*) > 4" |
Unless I'm mistaken, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using GroupBy with Where produces invalid SQL
Steps to reproduce
Produced SQL
Expected SQL
Further technical details
EF Core version: 2.1.0-preview1-28226
Database Provider: Microsoft.EntityFrameworkCore.Sqlite
Operating system: Windows 10 Pro
IDE: Visual Studio 2017 15.6 p3
The text was updated successfully, but these errors were encountered: