Grouping functions of oracle reinforcement exercises

Source: Internet
Author: User

Grouping functions of oracle reinforcement exercises

1. Show jobs with an average salary of> 2000

Select job, avg (sal) from emp group by job having avg (sal)> 2500;

2. Calculate the average salary of over 2000 jobs and the average salary of over 3000 jobs

Select job, avg (sal) From emp where sal> 2000 group by job having avg (sal)> 3000;

3. Find the highest and lowest salaries for each department

Select deptno, max (sal), min (sal) From emp group by deptno;

4. Find the highest and lowest salaries for each position in each department

Select deptno, max (sal), min (sal) from emp group by job, deptno;

SelectDeptno, job,Max(Sal ),Min(Sal)FromEmpWhereJobIs notnull groupJob, deptno;

5. display the sum of the average salary, highest salary, minimum wage and salary of employees whose job name contains "MAN"

Select avg (sal), max (sal), min (sal), sum (sal) from emp where job like '% MAN % ';

6. The number of employees in department 20 is displayed.

Select count (*) from emp where deptno = 20;

7. Show the names and average salaries of departments with an average salary greater than 2000

Select dname, avg (sal) From dept d, emp e where e. deptno = d. deptno group by dname having avg (sal)> 2000;

8. shows the average salary of each department over 2500 of all departments and jobs

Select deptno, job From emp group by deptno, job having avg (sal)> 2500;

9. The name of a job that contains "MAN" and whose average salary is greater than 1000 is displayed.

Select job, avg (sal) From emp group by job having avg (sal)> 1000, and job like '% MAN % ';

10. shows the average salary of the Department with the highest average salary

11. List jobs with a minimum wage of more than 1500

Select job From emp group by job having min (sal)> 1500;

12. List the number of employees and the average working life of each department

Select deptno, count (*), avg (sysdate-hiredate)/365) From emp group by deptno;

Select deptno, avg (months_between (sysdate, hiredate)/12) from emp group by deptno;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.