1、select max(sal) as 最高工资,min(sal) as 最低工资,deptno as 部门号 from emp where job = group by deptno;3 对于emp中最低工资小于1000的部门,列出job为的员工的部门号,最低工资,最高工资 select max(sal) as 最高工资,min(sal) as 最低工资,deptno as 部门号 from emp as b where job= and 1000(select min(sal) from emp as a where a.deptno=b.deptno) group by b.deptno
2、4 根据部门号由高而低,工资有低而高列出每个员工的姓名,部门号,工资 select deptno as 部门号,ename as 姓名,sal as 工资 from emp order by deptno desc,sal asc 5 写出对上题的另一解决方法 (请补充) 6 列出张三所在部门中每个员工的姓名与部门号 select ename,deptno from emp where deptno = (select deptno from emp where ename = ) 7 列出每个员工的姓名,工作,部门号,部门名 select ename,job,emp.deptno,dept.
3、dname from emp,dept where emp.deptno=dept.deptno 8 列出emp中工作为的员工的姓名,工作,部门号,部门名 select ename,job,dept.deptno,dname from emp,dept where dept.deptno=emp.deptno and job=9 对于emp中有管理者的员工,列出姓名,管理者姓名(管理者外键为mgr) select a.ename as 姓名,b.ename as 管理者 from emp as a,emp as b where a.mgr is not null and a.mgr=b.emp
4、no 10 对于dept表中,列出所有部门名,部门号,同时列出各部门工作为的员工名与工作 select dname as 部门名,dept.deptno as 部门号,ename as 员工名,job as 工作 from dept,emp where dept.deptno *= emp.deptno and job = 11 对于工资高于本部门平均水平的员工,列出部门号,姓名,工资,按部门号排序 select a.deptno as 部门号,a.ename as 姓名,a.sal as 工资 from emp as a where a.sal(select avg(sal) from em
5、p as b where a.deptno=b.deptno) order by a.deptno 12 对于emp,列出各个部门中平均工资高于本部门平均水平的员工数和部门号,按部门号排序 select count(a.sal) as 员工数,a.deptno as 部门号 from emp as a (select avg(sal) from emp as b where a.deptno=b.deptno) group by a.deptno order by a.deptno 13 对于emp中工资高于本部门平均水平,人数多与1人的,列出部门号,人数,按部门号排序 select coun
6、t(a.empno) as 员工数,a.deptno as 部门号,avg(sal) as 平均工资 from emp as a where (select count(c.empno) from emp as c where c.deptno=a.deptno and c.sal(select avg(sal) from emp as b where c.deptno=b.deptno)1 group by a.deptno order by a.deptno 14 对于emp中低于自己工资至少5人的员工,列出其部门号,姓名,工资,以及工资少于自己的人数 select a.deptno,a.
7、ename,a.sal,(select count(b.ename) from emp as b where b.sala.sal) as 人数 from emp as a where (select count(b.ename) from emp as b where b.sal5 - -sql structured query language -DML-Data Manipulation Language-数据操作语言 query information (SELECT), add new rows (INSERT), modify existing rows (UPDATE), del
8、ete existing rows (DELETE), perform a conditional update or insert operation (MERGE), see an execution plan of SQL (EXPLAIN PLAN), and lock a table to restrict access (LOCK TABLE). -DDL-Data Definition Language-数据定义语言 create, modify,drop, or rename objects (CREATE,ALTER,DROP,RENAME), remove all rows
9、 from a database object without dropping the structure (TRUNCATE), manage access privileges (GRANT,REVOKE), audit database use (AUDIT,NOAUDIT) and add a description about an object to the dictionary (COMMENT). -Transaction Control事务控制语句 save the changes(COMMIT) or discard the changes (ROLLBACK) made
10、 by DML statements. Also included in the transaction-control statements are statements to set a point or marker in the transaction for possible rollback (SAVEPOINT) and to define the properties for the transaction (SET TRANSACTION). Used to manage the properties of the database. There isonly one sta
11、tement in this category (ALTER SYSTEM). -DCL-Data Control Language-与开发关系不是很密切,用于权限的分配与回收 grant,revoke,data control -Session Control control the session properties (ALTER SESSION) and to enable/disable roles (SET ROLE). -System Control - select的用法 -每个员工的所有信息 select * from emp -每个人的部门编号,姓名,薪水 select d
12、eptno,ename,sal from emp;-每个人的年薪 select ename,sal*12 from emp;-计算2*3的值 select 2*3 from emp;-计算2*3的值(dual) select 2*3 from dual;select * from dual;-得到当前时间 select sysdate from dual -可以给列起别名,比如求每个人的年薪 select ename,sal*12 salperyear from emp;-如果别名中有空格,需要用双引号 select ename,sal*12 sal per year from emp;-如果
13、没有内容,则为空 select comm from emp;-当空字段参与计算,则结果是null -例如:计算每个人的全年的收入包括月薪和年终奖 select ename,sal*12+comm from emp;-可以将多个字符串拼在一起。比如:求每个人的薪水,格式为smith-sal-123 select ename|-sal-|sal from emp;-如果字符串中有单引号,需要用另外一个单引号转义,比如:这样一个字符串: hes friend s sal is-distinct 关键词的用法 -求有哪些个部门 select distinct deptno from emp -可以用来修饰多个字段。求有哪些个部门和job的组合 select distinct deptno,job from emp where关键词的用法 -可以是数值类型的等值判断。求10这个部门的所有员工 select * from emp where deptno=20 -可以是字符串类型的等值判断。求叫KING的这个人的信息 select * from emp where ename = KING-也可以是不等值判断。求薪水小于2000的员工信息 select
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1