码迷,mamicode.com
首页 > 数据库 > 详细

码字定式之SQL(2)

时间:2014-11-27 10:31:04      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   ar   sp   on   div   2014   

select 基本构成之经典格式
  1. select * from emp;
  2. select * from emp where empno>8000;
  3. select empno,ename,sal,comm from emp where sal<comm;
  4. select deptno,count(*) from emp group by deptno;
  5. select deptno,sum(sal) total_sal from emp where job=‘MANAGER‘ group by deptno;
  6. select job,count(distinct deptno) from emp where mgr is not null group by job order by job;
  1. select job,count(distinct deptno) from emp where mgr is not null group by job order by count(distinct deptno) desc,job;
  2. select job, count(distinct deptno) uniq_deptno from emp where mgr is not null group by job order by uniq_deptno desc, job;
  3. select deptno, to_char(hiredate,‘yyyy‘),count(*) from emp group by deptno,to_char(hiredate,‘yyyy‘);
排序是很耗资源的,所以是最后执行,大家应该记住这一点。
下面看一则需求。

bubuko.com,布布扣





码字定式之SQL(2)

标签:des   style   blog   http   ar   sp   on   div   2014   

原文地址:http://www.cnblogs.com/mahun/p/4125721.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!