经典sql语句

经典sql语句:
[code] 在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)


[/code]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值