摘要: HAVING使用子查询 //查询各部门平均工资,显示平均工资大于 //公司整体平均工资的记录 select deptno,avg(sal) from emp group by deptno having avg(sal)>(select avg(sal) from emp); 阅读全文
posted @ 2016-05-16 11:38 YunMan 阅读(881) 评论(0) 推荐(0) 编辑
摘要: FROM使用子查询 子查询结果充当一个临时表。 //子查询形成的临时表字段为NO,NAME,SAL select no,name from( select empno no,ename name,sal from emp ); //子查询形成的临时表字段为DEPTNO,AVG select dept 阅读全文
posted @ 2016-05-16 11:37 YunMan 阅读(840) 评论(0) 推荐(0) 编辑
摘要: b.多行子查询(适用于in,any,all条件) //查询与SCOTT和MARTIN在同一个部门的同事的编号和名称 select empno,ename from emp where deptno in ( select deptno from emp where ename in ('SCOTT' 阅读全文
posted @ 2016-05-16 11:36 YunMan 阅读(759) 评论(0) 推荐(1) 编辑
摘要: a.单行子查询(适用于>,<,=,>=,<=等条件) //查询工资最高的员工编号和员工名 select empno,ename from emp where sal=(select max(sal) from emp); //查询最新入职的员工编号和员工名 select empno,ename fr 阅读全文
posted @ 2016-05-16 11:36 YunMan 阅读(469) 评论(0) 推荐(0) 编辑
摘要: max():求最大值 min():求最小值 avg():求平均值 sum():求和 count():统计数量 //查询员工的最高工资 select max(sal) from emp; //查询员工的最低工资和平均工资 select min(sal),avg(sal) from emp; //查询所 阅读全文
posted @ 2016-05-16 11:35 YunMan 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 10.ORDER BY排序子句 用于指定将查询结果排序的字段。 //查询emp表所有记录,结果按ename升序排列 select empno,ename from emp order by ename asc;//asc可以省略,默认为asc //查询emp表所有记录,结果按sal降序排列 sele 阅读全文
posted @ 2016-05-16 11:34 YunMan 阅读(416) 评论(0) 推荐(0) 编辑
摘要: 9.过滤查询结果的重复记录 //查询员工职位类型,过滤重复结果 select distinct job from emp; //查询员工名字和职位,如果名字+职位都相同才过滤 select distinct ename,job from emp; //查询10部门员工从事哪些类型的职位 select 阅读全文
posted @ 2016-05-16 11:33 YunMan 阅读(244) 评论(0) 推荐(0) 编辑
摘要: 8.在WHERE中使用ANY和ALL条件 字段 >ANY(值1,值2,值3...):字段值大于集合任何一个 值就算满足条件。 字段 >ALL(值1,值2,值3...):字段值大于集合中所有 值才算满足条件。 上述也可以用<ANY,>=ANY,<=ANY. <ALL,>=ALL,<=ALL //查询工 阅读全文
posted @ 2016-05-16 11:32 YunMan 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 7.在WHERE中使用in和not in条件 字段 in (值1,值2,值3...):字段值在指定的集合元素中 //查询10,20,30,40这些部门的员工信息 select empno,ename from emp where deptno=10 or deptno=20 or deptno=30 阅读全文
posted @ 2016-05-16 11:30 YunMan 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 3.WHERE中使用is null和is not null //查询工资是null空值的人 select * from person where salary is null; //查询工资不为null的人 select * from person where salary is not null; 阅读全文
posted @ 2016-05-16 11:29 YunMan 阅读(190) 评论(0) 推荐(0) 编辑