Having clause:

-> By using having clause we can filter the records from intermediate result sets which are executed after the execution of group by clause. -> We are allowed to aggregate functions along with having clause. Query to display department name with corresponding average salaries for the department whose average salary is greater than 16000. -> select dept,avg(salary) as 'avgsal' from employees group by dept having avg(salary)>16000. Query to display department name along with maximum salaries for departments where minimum salary is not less than 15000. -> select dept,max(salary) as 'maxsal' from employees group by dept having min(salary) > 15000. Query to display employees details whose salaries are greater than the corresponding department average salaries. declare @t1 table;dept varchar(40);avgsal int; declare @t2 table;eid int;fname varchar(40);lname varchar(40),age int,salary int,dept varchar(20),doj date, insert into @t1 select dept,avg(salary) from employees groupby dept, declare @count int, select @count = count(*) from @t1 while(@count>0) begin declare @dn varchar(40) declare @avgsal int, select top1 @dn=dept,@avgsal=avgsal from @t1 insert into @t2 seect * from employees where dept=@dn and salary=@avgsal, delete @t1 where dept=@dn, set @count=@count-1, end select*from @t2