MySQL HAVING ClauseMySQL HAVING Clause is used with GROUP BY clause. It always returns the rows where condition is TRUE. Syntax:Parametersaggregate_function: It specifies any one of the aggregate function such as SUM, COUNT, MIN, MAX, or AVG. expression1, expression2, ... expression_n: It specifies the expressions that are not encapsulated within an aggregate function and must be included in the GROUP BY clause. WHERE conditions: It is optional. It specifies the conditions for the records to be selected. HAVING condition: It is used to restrict the groups of returned rows. It shows only those groups in result set whose conditions are TRUE. HAVING Clause with SUM functionConsider a table "employees" table having the following data. Here, we use the SUM function with the HAVING Clause to return the emp_name and sum of their working hours. Execute the following query: Simply, it can also be used with COUNT, MIN, MAX and AVG functions. Next TopicMySQL Grant Privilege |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India