Oracle-Query statements-grouping functions

Source: Internet
Author: User

/*The grouping function can no longer have normal columns in the SELECT clause, unless the column gives all the null values in group by to be grouped into a group filter SELECT from WHERE GROUPBY having an by-clause*/--find out the average salary for each jobSELECTJOB,AVG(SAL),MAX(SAL),MIN(SAL) fromEmpGROUP  byJOB; SELECT MAX(SAL) fromEMP;SELECTDEPTNO,AVG(SAL) fromEmpGROUP  byDEPTNO;--find the average salary for different jobs in each departmentSELECTDeptno,job,AVG(SAL) fromEmpGROUP  byDEPTNO, JOBORDER  byDeptno,job; --in a grouping function statement, each column that appears in the SELECT clause must appear now after group by.--unless it's a group function, and you need to follow the rules for using group functionsSELECTDEPTNO,AVG(SAL),MIN(ename) fromEmpGROUP  byDEPTNO;--grouped according to allowancesSELECTCOMM,COUNT(*) fromEmpGROUP  byCOMM;--find the average salary for employees with a salary greater than 2000 in each departmentSELECTDEPTNO,AVG(SAL) fromEmpWHERESAL> - GROUP  byDEPTNO;--Query The average salary of the department, if the average salary is less than 2000 filter outSELECTDEPTNO,AVG(SAL) fromEmpGROUP  byDEPTNO having AVG(SAL)> -;--Search for employees with a salary greater than or equal to 2500, group by job, and then find jobs with average pay greater than or equal to 3000SELECT *  fromEMP;-- -SELECT *  fromEmpWHERESAL>=2500;--5SELECTJOB,AVG(SAL) fromEmpWHERESAL>=2500 GROUP  byJOB;--3SELECTJOB,AVG(SAL) fromEmpWHERESAL>=2500 GROUP  byJOB having AVG(SAL)>= the;--2SELECTJOB,AVG(SAL) fromEmpWHERESAL>=2500 GROUP  byJOB having AVG(SAL)>= the ORDER  by AVG(SAL)DESC;

Oracle-Query statements-grouping functions

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.