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

QueryBuilder: Add support for HAVING #754

Open
blackcoder87 opened this issue Aug 27, 2023 · 0 comments
Open

QueryBuilder: Add support for HAVING #754

blackcoder87 opened this issue Aug 27, 2023 · 0 comments
Labels
Type: Enhancement The issue is a request for new functionality including changes, enhancements, refactors, etc.

Comments

@blackcoder87
Copy link
Member

The HAVING clause, like the WHERE clause, specifies selection conditions. The WHERE clause specifies conditions on columns in the select list, but cannot refer to aggregate functions. The HAVING clause specifies conditions on groups, typically formed by the GROUP BY clause. The query result includes only groups satisfying the HAVING conditions. (If no GROUP BY is present, all rows implicitly form a single aggregate group.)

The HAVING clause is applied nearly last, just before items are sent to the client, with no optimization. (LIMIT is applied after HAVING.)

The SQL standard requires that HAVING must reference only columns in the GROUP BY clause or columns used in aggregate functions. However, MySQL supports an extension to this behavior, and permits HAVING to refer to columns in the SELECT list and columns in outer subqueries as well.

SELECT COUNT(col1) AS col2 FROM t GROUP BY col2 HAVING col2 = 2;

SELECT user, MAX(salary) FROM users GROUP BY user HAVING MAX(salary) > 10;

Additional context
https://dev.mysql.com/doc/refman/5.7/en/select.html
https://dev.mysql.com/doc/refman/8.1/en/select.html
https://mariadb.com/kb/en/select/

@blackcoder87 blackcoder87 added the Type: Enhancement The issue is a request for new functionality including changes, enhancements, refactors, etc. label Aug 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement The issue is a request for new functionality including changes, enhancements, refactors, etc.
Projects
None yet
Development

No branches or pull requests

1 participant