oracle - groupby group learning

Group by using the packet 
        can not be directly used in the field of ordinary multi-line function, unless the group by 
        not directly using the one-way function in the multi-line function, unless the group by 
        group by learning: --- 1, packet data group by using multiple select lines function, packet field from table group by grouping field 
             --- 2, when the plurality of packet fields, the fields are grouped according to sequence, after a first packet is completed condition, the condition to use other packets sequentially. 
             --- 3, group by and order by can still be used in combination 
             --- 4 can be combined group and one-way function, note the use of the one-way function you must also use the query in 
        Query highest wages and number of employees 
          select max ( sal), count (*) from emp 
        query highest wages in different sectors of 
          the SELECT * deptno from emp the Order by 
          the SELECT deptno, max (SAL) from emp group by group to group deptno-- use query packet fields can appear in the query other fields still can not 
        query the number of employees in different jobs
              
          select * from emp for update
          select lower (job), count ( *) from emp group by lower (job) - the use of one-way functions are grouped 
        number of queries different jobs in different departments of 
          select deptno, job, count (* ) from emp group by deptno, job - use a combination of multi-field group 
          select deptno, job, count (* ) from emp group by deptno, job order by deptno 
        query different jobs in different departments of information and the number is greater than 1, 
          select count (*) from emp where count (*)> 3 Group by deptno 
          select deptno, the job, COUNT (*) from emp the WHERE COUNT (*)> 1 Group by deptno, the job the Order by deptno 
        number of different jobs in different departments of inquiry department number is greater than 10 
          select deptno , job, count (*) from emp where deptno> 10 group by deptno, job order by deptno 
        after using the screening group having 
        having to learn:
              - 1, when making use of the data after the screening group by group, where the multi-line functions can not appear, so using the new keyword having conditional screening 
             --2, where conditions are screened order of execution: from -> where ---> group - > select
             --3, the order having screening conditions: from -> Group by -> having -> the SELECT 
             --4, where the efficiency is higher than having, try not to use having the case can be used where the 
        queries are different and the number of different jobs in the information sector is greater than 1, 
        use the where clause to filter 
        sql execution sequence where a conditional statement: from -> where ---> Group -> the SELECT 
          the SELECT COUNT (*) from emp where COUNT (*) > 1 group by deptno, job 
        using a filter having statement 
        execution sequence having conditional statement: from - having> - -> Group by> the SELECT 
          the SELECT deptno, COUNT (*) from emp Group by deptno having COUNT (*) >. 5 
          SELECT DEPTNO, Job, COUNT (*) Group by DEPTNO from EMP, Job HAVING DEPTNO> 10 Order by DEPTNO

  

Guess you like

Origin www.cnblogs.com/eadela/p/11455469.html