经典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 ...
随机推荐
- JS 动画笔记
动画实现原理 核心原理:通过定时器setInterval()不断地移动盒子的位置 缓动动画原理 缓动的核心算法~~~~~~~~~~(目标值-现在的位置)/10 停止的条件是~~ ...
- 【工具】之001-CentOS7 最小化安装配置
写在前面 我很懒,,,不想敲一个命令一个命令敲... "偷懒是有前提的,不是之前,就是之后." 简述 CentOS 7 最小化安装版本:CentOS-7-x86_64-Minima ...
- Springboot日志LOGO改变和设计
每次启动Springboot的时候,SpringBoot都会打印一个LOGO,那么这个LOGO是可以关闭和改变的. 1.关闭Springboot的LOGO 2.改变Springboot的日志LOGO ...
- C#LeetCode刷题之#559-N叉树的最大深度(Maximum Depth of N-ary Tree)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4088 访问. 给定一个 N 叉树,找到其最大深度. 最大深度是指 ...
- C#LeetCode刷题之#345-反转字符串中的元音字母(Reverse Vowels of a String)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3935 访问. 编写一个函数,以字符串作为输入,反转该字符串中的元 ...
- Java爬取先知论坛文章
Java爬取先知论坛文章 0x00 前言 上篇文章写了部分爬虫代码,这里给出一个完整的爬取先知论坛文章代码. 0x01 代码实现 pom.xml加入依赖: <dependencies> & ...
- 一网打尽 Java 并发模型
本篇文章我们来探讨一下并发设计模型. 可以使用不同的并发模型来实现并发系统,并发模型说的是系统中的线程如何协作完成并发任务.不同的并发模型以不同的方式拆分任务,线程可以以不同的方式进行通信和协作. 并 ...
- postman with xdebug
Set the url with ?XDEBUG_SESSION_START=PHPSTORM and set a header Cookie: XDEBUG_SESSION=PHPSTORM
- 操作系统-中断(2)IA-32/Linux的向量中断方式
一.Intel定义下的异常和中断 不同体系和教材往往对异常和中断有不同的定义. Intel定义:中断是一种典型的由I/O设备触发的.与当前正在执行的指令无关的异步事件:而异常是处理器执行一条指令时,由 ...
- HYSBZ - 2243 树链剖分 + 线段树 处理树上颜色段数
用线段树处理颜色段数 记录区间内的颜色段数,区间右端点的颜色,区间右端点的颜色. int tr[maxn<<2], lc[maxn<<2], rc[maxn<<2] ...