1.在初次进入sql plus的时候无法连接到scott用户,因为被锁住了
scott账户下有emp dept salary grade的表,如果要用scott账户的话
用管理元权限去解锁,如登录system账户,运行 alert user scott account unlock; 解锁了就可以用conn scott/tiger这 个时候会要求改口令之后就可以开始练习了!
2.练习题
(1)在sales部门工作的人的姓名
SQL> select ename from emp where deptno in(select deptno from dept where dname='SALES');
(2)/*列出薪金高于公司平均薪金的所有员工,所在部门,上级领导,公司的工资等级*/
先找出薪金高于公司平均薪金的所有员工:SQL> select * from emp where sal>(select avg(sal) from emp);
在从这里面去查找所属部门和上级领导以及工资等级:
SQL> select e.ename,d.dname,m.ename,g.grade from emp e,emp m,dept d,salgrade g
where e.sal>(select avg(sal) from emp) and d.deptno=e.deptno and e.mgr=m.empno and e.sal between
losal and hisal;
(3)列出每个部门的员工数量,平均工资和平均服务期限
SQL> select count(*),avg(sal),avg(months_between(sysdate,hiredate)) from emp group by deptno;
select sysdate from dual;查看当前日期
months_between函数是算两个日期的间隔月数
查询的时候,首先要确定的是需要查询几个表。