MAKE FULL WEB APPLICATION WITH JUST SQL KNOWLEDGE? CLICK HERE
The SQL GROUP BY statement is used along with the SQL
aggregate functions like SUM to provide means of grouping the
result data set by certain database table column(s).
GROUP BY... was added to SQL because aggregate functions
(like SUM) return the aggregate of all column values every time
they are called, and without the GROUP BY function it was
impossible to find the sum for each individual group of column values.
It allows us to calculate aggregate of groups within our table.
The SQL HAVING clause is used to restrict conditionally
the output of a SQL statement, by a SQL aggregate function
used in your SELECT list of columns. You can't specify a fact in
a SQL WHERE clause against a column in the SELECT list for
which SQL aggregate function is used.
HAVING... was added to SQL because the WHERE keyword
could not be used against aggregate functions (like SUM), and without
HAVING... it would be impossible to test for result conditions.
This clause is applied after grouping is applied. Without the HAVING
keyword it would not be possible to test for function result conditions.
The syntax for the HAVING function is:
|