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函數是算兩個日期的間隔月數
查詢的時候,首先要確定的是需要查詢幾個表。