首页 > 其他 > 详细

分组案列总结:

时间:2017-10-04 13:20:56      阅读:230      评论:0      收藏:0      [点我收藏+]

         范例:显示所有非销售人员的工作名称以及从事同一工作雇员的月工资总和,并且要求满足从事同一工作雇员的月工资的合计大于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;

分组案列总结:

原文:http://www.cnblogs.com/Juvenile/p/7625330.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!