Oracle特殊查询 行列倒转 分页
--查询工资最高的前三名 (分页的感觉)
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特殊查询 行列倒转 分页的更多相关文章
- Oracle子查询相关内容(包含TOP-N查询和分页查询)
本节介绍Oracle子查询的相关内容: 实例用到的数据为oracle中scott用户下的emp员工表,dept部门表,数据如下: 一.子查询 1.概念:嵌入在一个查询中的另一个查询语句,也就是说一个查 ...
- oracle高级查询(实例基于scott用户四张表)
oracle高级查询(实例基于scott用户四张表) 分组查询 多表查询 子查询 综合实例 ====================================================== ...
- oracle表查询
使用scott用户中存在的emp.dept表等做演示 一.单表查询 查看表结构:desc dept; 查看所有列:select * from dept: 查询指定列:select ename,sal, ...
- 黑马oracle_day01:03.oracle的查询
01.oracle体系结构 02.oracle的基本操作 03.oracle的查询 04.oracle对象 05.oracle编程 黑马oracle_day01:03.oracle的查询 09scot ...
- 【软件实施面试】MySQL和Oracle联合查询以及聚合函数面试总结
软件实施面试系列文章第二弹,MySQL和Oracle联合查询以及聚合函数的面试总结.放眼望去全是MySQL,就不能来点Oracle吗?之前面过不少公司,也做过不少笔试题,现在已经很少做笔试题了.你肚子 ...
- Oracle层次查询
Oracle层次查询的语法如下: 下面根据两道“烧脑”的题具体来体现: 1. 根据时间先后顺序,十二星座的英文名称用逗号串起来为'Aries,Taurus,Gemini,Cancer,Leo,Virg ...
- 关于Oracle中查询的数字值的显示格式需要保留小数点后两位(或者三位,及其他位数)
关于Oracle中查询的数字值的显示格式需要保留小数点后两位(或者三位,及其... 方法一:使用to_char的fm格式,即: to_char(round(data.amount,2),'FM9999 ...
- Oracle参数化查询
Oracle参数化查询默认是根据顺序绑定的 select * from table where name=:p1 and (select id from table2 where name=:p1); ...
- Lucene查询索引(分页)
分页查询只需传入每页显示记录数和当前页就可以实现分页查询功能 Lucene分页查询是对搜索返回的结果进行分页,而不是对搜索结果的总数量进行分页,因此我们搜索的时候都是返回前n条记录 package c ...
随机推荐
- 如何用Fireworks制作经典的扫光字GIF动画
1.首先我们把背景选为黑色.再输入文字用白色填充,注意调整文字之间的间隔. 2.选中字体,对其进行转换为路径文件. 3.对间隔再做少许调整. 4.复制文字改为黑色,做平移,出现立体效果. 5.再复制一 ...
- Spring Data MongoDB 分页查询
在上篇文章 Spring Data MongoDB 环境搭建 基础上进行分页查询 定义公用分页参数类,实现 Pageable 接口 import java.io.Serializable; impor ...
- PRML读书笔记——线性回归模型(上)
本章开始学习第一个有监督学习模型--线性回归模型."线性"在这里的含义仅限定了模型必须是参数的线性函数.而正如我们接下来要看到的,线性回归模型可以是输入变量\(x\)的非线性函数. ...
- 谁动了我的Mac ??
教大家一种方法,看看有没有人在自己对Mac睡眠后对其进行唤醒 一:应用程序里有个控制台,可以将这个打开,输入wake reason 二:在终端输入:syslog |grep -i "Wake ...
- hbase启动问题记录
昨天测试环境的Hbase启动有问题,日志中显示: transaction type: 1 error: KeeperErrorCode = NoNode for /hbase hmaster等其他进程 ...
- 【 PostgreSQL】工作中常用SQL语句干货
接触gp数据库近一年的时间,语法上和其他数据库还是有些许不同,工作中常用的操作语句分享给大家! -- 建表语句 create table ods.ods_b_bill_m ( acct_month t ...
- Exchange 接收连接器(Client、Default)区别,OUtlook实际测试
CAS就是接收连接器(110,995): Server Config--Client Access:POP3 and IMAP4:POP3设置 HUB就是发送连接器(25,587) Server Co ...
- 简单转java-web项目
- charles license key
Download: http://www.charlesproxy.com/ (Official Web-site) Registered name: anthony ortolani License ...
- markdown编辑器安装
打算使用MarkDown了,打算整理自己的知识了. 多年以前,喜欢将自己看到好东西,转载在博客.或者将遇到过的问题以及解决方案,记录在博客.06毕业后为了生活折腾,Tom网上的博客无暇东顾,等稳定闲下 ...