经典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 ...
随机推荐
- 操作属性、操作样式 - DOM编程
1. 操作属性 1.1 HTML 属性与 DOM 属性的对应 <div> <label for="username">User Name: </lab ...
- JS 图片跟随鼠标移动案例
css代码 img { position: absolute; /* top: 2px; */ width: 50px; height: 50px; } HTML代码 <img src=&quo ...
- Dubbo系列之 (二)Registry注册中心-注册(1)
引导 dubbo的服务的注册与发现,需要通过第三方注册中心来协助完成,目前dubbo支持的注册中心包括 zookeeper,consul,etcd3,eureka,nacas,redis,sofa.这 ...
- html定时跳转页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 02树莓派4B—C语言编程——PWM
01树莓派直接输出PWM波 —— 硬件PWM程序 (推荐使用) #include <stdio.h> #include <wiringPi.h> #include <s ...
- 如何使用screen命令
大家好,我是良许. 很多时候,我们都需要执行一些需要很长时间的任务.如果这时候,你的网络连接突然断开了,那么你之前所做的所有工作可能都会丢失,所做的工作可能都要重做一遍,这会浪费我们许多的时间,非常影 ...
- Linux系统中有趣的命令(可以玩小游戏)
Linux系统中有趣的命令(可以玩小游戏) 前言 最近,我在看一些关于Linux系统的内容,这里面的内容是真的越学越枯燥,果然学习的过程还是不容易的.记得前几个月初学Linux时,有时候就会碰到小彩蛋 ...
- 使用Kali中的Metasploit生成木马控制Windows系统
一.概念:Kali基于debin的数字取证系统,上面集成了很多渗透测试工具,其前身是BT5 R3(BtackTrack). 其中Metasploit是一个综合利用工具,极大的提高了攻击者的渗透效率,使 ...
- cinder api启动过程源码分析
1.启动cinder-api服务 当你通过cinder-api命令(如:/usr/bin/cinder-api --config-file /etc/cinder/cinder.conf)启动api服 ...
- Robot Framework(6)——案例分层
上一篇以gogomall的登录为例,记录了一个简单的登录流程的脚本,在实际应用中,当流程发生一些小的变动,或者前端代码改变,导致元素选择器失效,我们维护脚本的成本就比较大,需要一个一个去修改,所以,有 ...