唐僧还在拜佛求经路。  

         范例:显示所有非销售人员的工作名称以及从事同一工作雇员的月工资总和,并且要求满足从事同一工作雇员的月工资的合计大于5000,显示的结果按照月工资的合计升序排列;
          第一步:查询所以人非销售人员的信息。
            select  *
            from scott.emp
            where job<>‘SALESMAN’;
          第二步:按照职位进行分组,而后求出工资的总支出:
             select  job,SUM(sal)
            from scott.emp
            where job<>‘SALESMAN’
            group by  job;
          第三部:分组后的数据进行再次筛选,使用HAVING语句
            select  job,SUM(sal)
              from scott.emp
              where job<>‘SALESMAN’
              group by  job
              having sum(sal)>5000;
          第四步:按照月工资的合计升序排列;使用order by
            select  job,SUM(sal) sum
              from scoot.emp
              where job<>‘SALESMAN’
              group by  job
              having sum(sal)>5000
              order by sum;
        范例二:查询出所有领取佣金的雇员的人数,平均工资。

            select ’领取佣金‘ info ,count(*), avg(sal)
            from scott.emp
            where comm is not null
            UNION
            select '不领取佣金' info, count(*),avg(sal)
            from scott.emp
            where comm is null;

posted on 2017-10-04 10:30  唐僧还在拜佛求经路。  阅读(184)  评论(0编辑  收藏  举报