--查询工资最高的前三名 (分页的感觉)
select * from
(select * from emp order by sal desc) t
where rownum <=3
--查询工资最高的4到6名 (分页-->排序 行号 选择三步)
select *
from (select t.*,rownum rn from (select * from emp order by sal desc) t) m where m.rn >= 4 and m.rn<=6

select *
from (select t.*,rownum rn from (select * from emp order by sal desc) t) m where m.rn between 4 and 6

select *
from (select e.*,row_number() over(order by e.sal desc) rn from emp e) t
where t.rn between 4 and 6
--查询每年入职的员工个数
select count(*), to_char(hiredate,'yyyy') from emp group by to_char(hiredate,'yyyy')
--把上面查询的表行列倒转
select count(*), to_char(hiredate,'yyyy') from emp group by to_char(hiredate,'yyyy')

select
sum(num) "Total",
avg(decode(hireyear,'1980',num)) "1980",
sum(decode(hireyear,'1981',num)) "1981",
max(decode(hireyear,'1982',num)) "1982",
min(decode(hireyear,'1987',num)) "1987"
from
(select count(*) num, to_char(hiredate,'yyyy') hireyear from emp group by to_char(hiredate,'yyyy')) t
--交集 两个集合共同的元素
select * from emp where deptno=20
intersect
select * from emp where sal>2000
--并集 两个集合所有的元素
--不去重
select * from emp where deptno=20
union all
select * from emp where sal>2000
--去重
select * from emp where deptno=20
union
select * from emp where sal>2000
--差集 A有B没有的元素
select * from emp where deptno=20
Minus
select * from emp where sal>2000

Oracle特殊查询 行列倒转 分页的更多相关文章

  1. Oracle子查询相关内容(包含TOP-N查询和分页查询)

    本节介绍Oracle子查询的相关内容: 实例用到的数据为oracle中scott用户下的emp员工表,dept部门表,数据如下: 一.子查询 1.概念:嵌入在一个查询中的另一个查询语句,也就是说一个查 ...

  2. oracle高级查询(实例基于scott用户四张表)

    oracle高级查询(实例基于scott用户四张表) 分组查询 多表查询 子查询 综合实例 ====================================================== ...

  3. oracle表查询

    使用scott用户中存在的emp.dept表等做演示 一.单表查询 查看表结构:desc dept; 查看所有列:select * from dept: 查询指定列:select ename,sal, ...

  4. 黑马oracle_day01:03.oracle的查询

    01.oracle体系结构 02.oracle的基本操作 03.oracle的查询 04.oracle对象 05.oracle编程 黑马oracle_day01:03.oracle的查询 09scot ...

  5. 【软件实施面试】MySQL和Oracle联合查询以及聚合函数面试总结

    软件实施面试系列文章第二弹,MySQL和Oracle联合查询以及聚合函数的面试总结.放眼望去全是MySQL,就不能来点Oracle吗?之前面过不少公司,也做过不少笔试题,现在已经很少做笔试题了.你肚子 ...

  6. Oracle层次查询

    Oracle层次查询的语法如下: 下面根据两道“烧脑”的题具体来体现: 1. 根据时间先后顺序,十二星座的英文名称用逗号串起来为'Aries,Taurus,Gemini,Cancer,Leo,Virg ...

  7. 关于Oracle中查询的数字值的显示格式需要保留小数点后两位(或者三位,及其他位数)

    关于Oracle中查询的数字值的显示格式需要保留小数点后两位(或者三位,及其... 方法一:使用to_char的fm格式,即: to_char(round(data.amount,2),'FM9999 ...

  8. Oracle参数化查询

    Oracle参数化查询默认是根据顺序绑定的 select * from table where name=:p1 and (select id from table2 where name=:p1); ...

  9. Lucene查询索引(分页)

    分页查询只需传入每页显示记录数和当前页就可以实现分页查询功能 Lucene分页查询是对搜索返回的结果进行分页,而不是对搜索结果的总数量进行分页,因此我们搜索的时候都是返回前n条记录 package c ...

随机推荐

  1. AJAX 概念 优势 发展前景 工作原理 底层技术 状态 缺点 框架

    1. 概念 Ajax asynchronous JavaScript and XML , 异步js和xml. 这种解释已经过时了, 现在ajax就是, 允许浏览器和服务器通信, 而无需刷新当前页面的技 ...

  2. .net C# Sql数据库SQLHelper类

    using System;using System.Collections.Generic;using System.Text;using System.Collections;using Syste ...

  3. restful知识点之三restframework认证-->权限-->频率

    认证.权限.频率是层层递进的关系 权限业务时认证+权限 频率业务时:认证+权限+频率 局部认证方式 from django.conf.urls import url,include from djan ...

  4. C#--动态加载DLL,通过反射调用参数,方法,窗体

    一些文章: 反射插件插件 http://bbs.csdn.net/topics/391950257?page=1 反射窗体 http://www.sufeinet.com/thread-2984-1- ...

  5. Python用户交互-密码不可见

    输入密码时若让用户不可见,可以使用getpass模块中的getpass方法 # 输入密码时若想要不可见,使用getpass模块中getpass方法即可 import getpass pwd=getpa ...

  6. EF6 code first 新建项目注意问题

    1.一开始就建立自动迁移模式 打开Package Manager Console,确保Package source是nuget.org 命令行输入: enable-migrations 然后第一次运行 ...

  7. Azure Linux 虚机上配置 RAID 的常见问题及解决方案

    简介 独立硬盘冗余阵列(RAID, Redundant Array of Independent Disks),简称磁盘阵列.能增强数据集成度,增强容错功能,增加处理量或容量.详情参见这篇文章. 配置 ...

  8. 音乐mp4网站 汽车服务工程 张旭

  9. JavaScript中的值和引用

    JavaScript5中有6种基本数据类型:undefined.null.布尔值(Boolean).字符串(String).数值(Number).对象(Object) ES6中新引入一种原始数据类型: ...

  10. JavaScript的事件概述以及事件对象,事件流

    事件处理程序 JavaScript 事件对象是由访问 Web 页面的用户引起的一系列操作,例如:用户点击页面上的某个按钮或者鼠标移动到页面的某个图片上而产生一系列的互动的反馈. 我们通过为指定事件绑定 ...