Skip to content

References in GROUP BY / HAVING should be allowed to match SELECT aliases. #7095

@nicktobey

Description

@nicktobey

Reproduction steps:

CREATE table xy (x int primary key, y int, unique index y_idx(y));
insert into xy values (1,0), (2,1), (0,2), (3,3);
select y as z from xy group by (y) having AVG(z) > 0;

MySQL output:

+------+
| z    |
+------+
|    1 |
|    2 |
|    3 |
+------+

Dolt output:

column "z" could not be found in any table in scope.

When resolving references in aggregate expressions, MySQL prefers binding to table columns over SELECT aliases. But it can still bind to a SELECT alias if no table column matches. The above example should work by binding z to the y as z alias in the SELECT.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions