经典sql语句:
在oracle中,每一条记录都有一个rowid,rowid在整个数据库中是唯一的,rowid确定了每条记录是oracle中的哪一个数据文件、块、行上。在重复的记录中,可能所有列的内容都相同,但rowid不会相同。
<第一个经典sql语句> decode和case when的使用
分别用case和decode函数列出员工所在的部门,deptno=10显示'部门 10',
deptno=20显示'部门 20'
deptno=30显示'部门 30'
deptno=40显示'部门 40'
否则为'其他部门'
select ename,
case deptno
when 10 then
'部门10'
when 20 then
'部门20'
when 30 then
'部门30'
when 40 then
'部门40'
else
'其他部门'
end 工资情况
from scott.emp
select ename,
decode(deptno,
10,
'部门10',
20,
'部门20',
30,
'部门30',
40,
'部门40',
'其他部门') 工资情况
from scott.emp
<第二个经典sql语句> 分页相关
查找出部门10和部门20中,工资最高第3名到工资第5名的员工的员工名字,部门名字,部门位置
select a.ename, dname, loc
from (select *
from (select rownum rn, deptno, empno, sal, ename
from (select deptno, empno, sal, ename
from scott.emp
where deptno in (10, 20)
and rownum <= 5
order by sal desc))
where rn between 3 and 5) a,
scott.dept b
where a.deptno = b.deptno
<第三个经典sql语句> 删除重复记录
delete from 表名 e
where e.rowid >
(select min(x.rowid) from 表名 x where x.empno = e.empno)
经典SQL语句下载地址