Oracle Learning Article Five: Group functions, grouping statistics

Source: Internet
Author: User

Common group functions:
1.ccount () to find out the total number of records.
2.max () to find out a set of maximum values
3.min () to find a minimum set of values
4.avg () to find the average
5.sum () summation


--1. Statistics of Employees:
Select COUNT (empno) from EMP;

--2. Find out the most high-paying capital
Select Max (SAL) from EMP;

--3. Finding the minimum wage
Select min (sal) from EMP;

--4. Finding the average salary
Select AVG (SAL) from EMP;

--Query the number of employees in each department
Select Deptno,count (empno) from the EMP Group by Deptno

--Query the average salary of each department
Select Deptno,avg (SAL) from the EMP Group by Deptno
Note: Grouping functions can only be used alone, or you can specify grouping criteria, which allows you to query the grouping criteria.
Select Empno,count (SAL) from EMP;---cannot execute

Select Deptno,avg (SAL) from EMP where AVG (SAL) >2000 GROUP by deptno--cannot execute
----NOTE: The grouping function cannot be used as a condition in hwere and can only be used in the having.
Select Deptno,avg (SAL) from the EMP GROUP by DEPTNO have avg (SAL) >2000

Select Max (SAL) from the EMP GROUP by deptno;--nested grouping functions can only be used separately

--Query the job name of the non-salesperson, and the sum of the salary of the person who is engaged in the same job, and to meet the sum of the work performed on the same job is greater than 5000, arrange the payroll total ascending.
Select Job, sum (SAL) Su from emp where Job <> ' salesman ' GROUP by job have sum (SAL) >5000 order by Su;

Oracle Learning Article Five: Group functions, grouping statistics

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.