经典SQL问题:Top 10%
学生表:
create table hy_student(
id number(4,0) primary key,
name nvarchar2(20) not null,
score number(3,0) not null)
充值:
insert into hy_student
select rownum,dbms_random.string('*',dbms_random.value(1,20)),dbms_random.value(0,100)
from dual
connect by level<201
order by dbms_random.random
第一步把学生按成绩逆序排列:
select * from hy_student order by score desc
第二步给加伪列:
select rownum as rn,a.* from (select * from hy_student order by score desc) a
最后就可以检出前10%的精英了:
select b.* from (select rownum as rn,a.* from (select * from hy_student order by score desc) a) b where b.rn<= (select count(*) from hy_student)/10
结果:

--2020-04-02--
以上用到的全部SQL:
create table hy_student(
id number(4,0) primary key,
name nvarchar2(20) not null,
score number(3,0) not null) insert into hy_student
select rownum,dbms_random.string('*',dbms_random.value(1,20)),dbms_random.value(0,100)
from dual
connect by level<201
order by dbms_random.random commit; select * from hy_student order by score desc select rownum as rn,a.* from (select * from hy_student order by score desc) a select b.* from (select rownum as rn,a.* from (select * from hy_student order by score desc) a) b where b.rn<= (select count(*) from hy_student)/10
经典SQL问题:Top 10%的更多相关文章
- SQL Server: Top 10 Secrets of a SQL Server Expert
转载自:http://technet.microsoft.com/en-us/magazine/gg299551.aspx Many companies have downsized their IT ...
- sql server top 10 IO性能查询
use master go ), ((case qs.statement_end_offset then datalength(qt.text) else qs.statement_end_offse ...
- Top 10 steps to optimize data access in SQL Server
2009年04月28日 Top 10 steps to optimize data access in SQL Server: Part I (use indexing) 2009年06月01日 To ...
- SQL Server’s Storage Top 10 Best Practices
好文章, 简明扼要. Storage Top 10 Best Practices http://technet.microsoft.com/en-us/library/cc966534.aspx
- 经典SQL语句大全
一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备 ...
- 【转载】经典SQL语句大全
[原文地址]http://www.cnblogs.com/yubinfeng/archive/2010/11/02/1867386.html 一.基础 1.说明:创建数据库CREATE DATABAS ...
- 20160411002 经典SQL语句大全
一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备 ...
- 经典SQL语句大全以及50个常用的sql语句
经典SQL语句大全 一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql serv ...
- 经典sql语句
经典SQL语句大全 一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql serv ...
- [转] - 经典SQL语句大全
经典SQL语句大全 一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql serv ...
随机推荐
- 2020-06-25:B+树和B树有什么区别?
福哥答案2020-06-25: B树:1.叶子节点和非叶子节点都存数据.2.数据无链指针.B+树:1.只有叶子节点存数据.2.数据有链指针.B树优势:1.靠近根节点的数据,访问速度快.B+树优势:1. ...
- sql 语句(精品)
GROUP BY: select avg(latency),projectName,data_trunc('hour'm\,_time_) as hour group by projectName,h ...
- 精讲响应式webclient第1篇-响应式非阻塞IO与基础用法
笔者在之前已经写了一系列的关于RestTemplate的文章,如下: 精讲RestTemplate第1篇-在Spring或非Spring环境下如何使用 精讲RestTemplate第2篇-多种底层HT ...
- 非对称加密与HTTPS(转)
序:HTTPS更安全,为什么? 因为HTTP协议本身毫无安全性可言. 当你访问一个纯HTTP的网站(以及与这个网站有任何网络交互)时,你发出去一个请求.在这个请求到达网站服务器的路途上,不管是你家的路 ...
- RSA非对称加密(java实例代码)
使用RSA对WebService传递的信息加密解密的基本思想是:服务器端提供一个WebService方法String getServerPublicKey(),客户端可以以此得到服务器端的公钥,然后使 ...
- GRMS_README
基于Hadoop的商品推荐系统 基于特征:基于行为:具有了一定的历史特征. 基于用户: 基于商品: 推荐结果=用户的购买向量*物品的相似度矩阵 物品的相似度:物品的共现次数 1.项目名:GRMS2.添 ...
- Mybatis入门(四)------联表查询
Mybatis联表查询 一.1对1查询 1.数据库建表 假设一个老师带一个学生 CREATE TABLE teacher( t_id INT PRIMARY KEY, t_name VARCHAR(3 ...
- k8s 辨析 port、NodePort、targetPort、containerPort 区别
刚接触 k8s 涉及到端口到内容较多,容易混淆,这里整理如下: 目录 nodePort port targetPort containerPort 参考文章 nodePort nodePort 提供了 ...
- quartz表(11张)
/* Navicat Premium Data Transfer Source Server : 本地连接 Source Server Type : MySQL Source Server Versi ...
- 不要再学 JSP 了,学 SpringBoot + Thymeleaf + Vue吧
老读者就请肆无忌惮地点赞吧,微信搜索[沉默王二]关注这个在九朝古都洛阳苟且偷生的程序员.本文 GitHub github.com/itwanger 已收录,里面还有我精心为你准备的一线大厂面试题. 读 ...