首页 > 代码库 > 码字定式之SQL(2)
码字定式之SQL(2)
select 基本构成之经典格式
select * from emp;
select * from emp where empno>8000;
select empno,ename,sal,comm from emp where sal<comm;
select deptno,count(*) from emp group by deptno;
select deptno,sum(sal) total_sal from emp where job=‘MANAGER‘ group by deptno;
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;
select job, count(distinct deptno) uniq_deptno from emp where mgr is not null group by job order by uniq_deptno desc, job;
select deptno, to_char(hiredate,‘yyyy‘),count(*) from emp group by deptno,to_char(hiredate,‘yyyy‘);
排序是很耗资源的,所以是最后执行,大家应该记住这一点。
下面看一则需求。
来自为知笔记(Wiz)
码字定式之SQL(2)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。