Oracle_ Multi-line function

Source: Internet
Author: User

Oracle_ Multi-line function

Multiline function min (), Max (), count (), SUM (), AVG ()
--1.1 Statistics of the company's maximum wage, minimum wage and total number --for null values to skip directly, do not operate--max,min,count can operate on any typeSelect max(sal ), Min(sal),Count(empno) From emp; select  max (sal ), Span style= "Color:windowtext" >  min ( sal ), count ( comm )   From emp Select max(sal ), Min(sal),count(Mgr) from emp;  Select sum(comm), avg(comm) from emp; Select max(ename), min(hiredate) from EMP ;
--2. Count the number of records in the EMP tableSelect Count(*) from emp; Total number of department employees with--2.1 statistics Department Number 10 Select Count(*) from emp where deptno=ten;
--3. Group BY, the order by is always put in the last--to count the department number and number of employees in each department and sort them by department numberSelect deptno, Count(*) from the EMP GROUP BY Deptno order by deptno;  --3.1 for each department number, number, total wage, average salary, maximum wage, minimum wageSelectdeptno, Count(*), Sum(sal), Avg(sal), Max(sal), Min(sal) FromEMPGroup ByDeptnoOrder By Avg (sal); Select Count(*), Sum(sal), Avg(sal), Max(sal), Min(sal) FromEMPGroup ByDeptnoOrder By Avg (sal);   --3.2 count the number of each department, excluding the department numbered 30 --Write the WHERE clause first, then write group bySelect deptno, Count(*) from emp where deptno<>30 Group by deptno;
-4. Statistics of average wage per department, excluding departments with average wage less than 2000multi-line function not allowed in--WHERE clause--having After grouping is complete, filter (cannot use alias to judge), having grammar and where basically consistentSelect deptno, avg(sal) from the EMP group by Deptno has avg(sal) >=; Select deptno, avg(sal) from the EMP group by Deptno having avg(sal) >= and deptno< >;
Practice
--In the EMP table, list jobs with a minimum wage of less than 2000Select Job,min(sal) from emp Group by Job having min(sal) <;  --a combination of departments and work pairings with average wage greater than 1200Select deptno,job,avg(sal) from emp Group by Deptno, Job has avg(sal) >;

-average wage of a department with a statistical population of less than 4Select deptno,avg(sal),Count(*) from emp Group by Deptno have count(*) <4;  -Statistics of the highest wages in each department, excluding the department with the highest wage of less than 3000Select from emp Group by deptno have Max(sal) > ;



Oracle_ Multi-line function

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.