Straight out of Books Online, but i believe it answers the first part of your question !!
HAVING
Specifies a search condition for a group or an aggregate. HAVING can be used only with the SELECT statement. It is usually used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause.
By aggregate Function, if you mean in line function, which return a single Value, then Yes i believe that you can !
If you are taking about SQL in built function Like COUNT or AVG, then YES once again you can do this !
Aggregate functions are intended for use in the HAVING clause, not the WHERE. Other than the aggregate functions, the key difference between the two is when they are applied.
The WHERE conditions are applied for each row of original data, as they are read, before the selected fields are extracted.
The HAVING conditions are applied after the selected fields are extracted, after any WHERE conditions and after any GROUP BY groupings are applied.
avoid using selections by Having as they are made after the all recordset is retrieved, a lot time and ressource consuming !!
So limit the having clause to aggregate selections when it's not possible another way;
All other selections must be made in the where clause (or the on clause sometimes)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.