Emp
Name deptno job sal
Scott 10 Clerk 5000
Allen 10 Clerk 7000
Smith 20 Sales 8000
Tom 30 IT 6000
Q1 Display Avg sal and sum of sal of employees?
Answer: Select avg(sal), sum(sal) from emp
Q2. Display Sum of Sal, deptno of employees whose Sum of Sum sal is
in the range of 20000 to 50000
Answer: Select Sum(sal),deptno from emp group by deptno having
sum(sal) between 20000 and 50000
Q3. Display Maximum sal , deptno of employees whose maximum sal is
greater than 1000?
Answer: Select max(sal),deptno from emp group by deptno having
sum(sal)>1000
Q4. Find out how many employees have Sum of sal greater than 1000?
Answer: Select Count(name) from emp having sum(sal)>1000
Q5. Differentiate Between Having and Where Clause
Answer: Where is used to implement condition
Having is used to group and then implement condition
Q6. Display sum of sal, deptno,job of employees whose sum of sal is
greater than 3000 and their job starts with "C”
Answer: Select sum(sal),deptno,job from emp where job like ‘C%’
group by deptno,job having sum(sal)>3000