/*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