oracle数据库基本查询操作

一,oracle数据库基本查询

以oracle自带EMP表示为例

--降序
SELECT * FROM emp e ORDER BY  sal desc
--分页查询
select temp.* fromSELECT ROWNUM rn , e.* FROM emp e ORDER BY  sal desctemp where ROWNUM between 0 and 3

--分页查询,查第二页
select * from emp order by sal desc;
select * from (select rownum rn ,temp.* from (select * from emp order by sal desc) temp where rownum<=6) where rn >=4

--排序
select rownu,e.*, rank() over (order by sal desc) as rank from emp e where;
select empno,deptno,ename,sal,DENSE_RANK() over(partition by deptno order by sal desc) as rank from emp;

--2,查询每个部门薪水第二高的员工基本信息(包含并列第二)
SELECT * FROM (
       SELECT E.*,DENSE_RANK()OVER(PARTITION BY DEPTNO ORDER BY SAL DESC) AS DRANK FROM EMP E
) E
WHERE DRANK = 2;


--显示职员的就职年度
SELECT E.*,TO_CHAR(HIREDATE,'YYYY') 年度 FROM EMP

--使用round()函数将入职日期四舍五入到年份
select ename,round(to_char(hiredate,'yyyy'))年度 from emp e;

select deptno from emp group by deptno;
---列出至少有一个雇员的所有部门
select * from dept where deptno in (select deptno from emp group by deptno having count(*) >=1);


--列出薪资比Smith多的所有雇员
select * from emp where sal > (select sal from emp where ename = 'SMITH');

--列出所有“CLERK”(办事员)的姓名及其部门名称

select e.ename,d.dname,e.job from emp e,dept d where e.deptno = d.deptno and e.job ='CLERK';

-- 列出各种工作类别的最低薪金,显示最低薪金大于1500的记录
select job,min(sal) from emp group by  job having min(sal) > 1500;

--找出各月最后一天受雇的所有雇员
SELECT * FROM EMP WHERE HIREDATE = LAST_DAY(HIREDATE);
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值