Saturday, August 1, 2015

SQL tutorial - lesson 11 - having clause

Having is used when you are using aggregate functions in the the statement. for example you cannot use where clause when you are using aggregate functions but having clause can be used

both where and having clause can be used for conditions but where cannot be used if you are using aggregate functions.

syntax:

select * from employees where emp region = "USA" Having  avg(sal) > 25000;

In the above statement you cannot put where in the place of having as it is aggregate.

when you run the above statement sql will return the employee details whose region is USA with the average salary more than 25000.

No comments:

Post a Comment