SQL – HAVING Clause

SQL – HAVING Clause: Here, we will figure out how to utilize conditions on the gatherings framed by GROUP BY?

Having Clause is utilized to set conditions on the gatherings framed from GROUP BY, it likewise utilizes total functions.

Syntax:

SELECT column1, column2, ...  FROM table_name 
WHERE condition 
GROUP BY column1, column2, ... 
HAVING condition;

Here,

  • Column_names: are the name of the fields in the table
  • table_name: name of the table from which we need to bring information
  • condition: use to channel information

Following are the functions that can be utilized with having the condition

  • Check – includes a number of lines in a table
  • AVG – figure the normal of the given values
  • MAX – returns limit of the given values
  • MIN – returns least of the given values
  • Whole – figures the total of the given values
  • STDDEV – figures standard deviation

Test table (Student),

SQL - HAVING Clause

1) Count number of urban areas

SELECT * FROM Student 
GROUP BY City 
HAVING COUNT(City) >1;
SQL - HAVING Clause

2) To show understudies whose imprints are more noteworthy than 89 in material science?

SELECT * FROM Student 
GROUP BY City 
HAVING MAX(physics)>89;
SQL - HAVING Clause

Leave a Comment

error: Alert: Content is protected!!