Skip to content

Fix grouped count aggregation on SQL Server#778

Open
apples-kksk wants to merge 1 commit into
sqlkata:mainfrom
apples-kksk:fix/sqlserver-groupby-removal-774
Open

Fix grouped count aggregation on SQL Server#778
apples-kksk wants to merge 1 commit into
sqlkata:mainfrom
apples-kksk:fix/sqlserver-groupby-removal-774

Conversation

@apples-kksk

@apples-kksk apples-kksk commented May 12, 2026

Copy link
Copy Markdown

Requested

Issue #774 reports that SQL Server compilation removes GROUP BY from grouped count queries.

Implemented

  • Preserve grouped query shape when transforming single-column AsCount() aggregate queries.
  • Wrap grouped counts in an outer COUNT(*) query while keeping the inner GROUP BY.
  • Added a SQL Server regression test for GroupBy(...).AsCount().

Not covered

No changes to distinct aggregate behavior or unrelated compiler output.

Validated

  • dotnet test sqlkata.sln --filter CountWithGroupBy
  • dotnet build sqlkata.sln
  • git diff --check

Also ran full dotnet test sqlkata.sln; non-MySQL tests passed, while 11 MySqlExecutionTest cases failed because no MySQL test service was available.

@apples-kksk apples-kksk changed the base branch from master to main May 13, 2026 09:03
@apples-kksk apples-kksk force-pushed the fix/sqlserver-groupby-removal-774 branch from ad70835 to a18729b Compare May 13, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant