您的位置:首页 > 博客中心 > 数据库 >

码字定式之SQL(2)

时间:2022-03-14 03:03

select 基本构成之经典格式

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





热门排行

今日推荐

热门手游