学生表:

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%的更多相关文章

  1. 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 ...

  2. sql server top 10 IO性能查询

    use master go ), ((case qs.statement_end_offset then datalength(qt.text) else qs.statement_end_offse ...

  3. 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 ...

  4. SQL Server’s Storage Top 10 Best Practices

    好文章, 简明扼要. Storage Top 10 Best Practices http://technet.microsoft.com/en-us/library/cc966534.aspx

  5. 经典SQL语句大全

    一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备 ...

  6. 【转载】经典SQL语句大全

    [原文地址]http://www.cnblogs.com/yubinfeng/archive/2010/11/02/1867386.html 一.基础 1.说明:创建数据库CREATE DATABAS ...

  7. 20160411002 经典SQL语句大全

    一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备 ...

  8. 经典SQL语句大全以及50个常用的sql语句

    经典SQL语句大全 一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql serv ...

  9. 经典sql语句

    经典SQL语句大全 一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql serv ...

  10. [转] - 经典SQL语句大全

    经典SQL语句大全 一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql serv ...

随机推荐

  1. CentOS7 安装 Nexus

    CentOS7 安装 Nexus 所需软件包 jdk-8u231-linux-x64.tar.gz nexus-3.24.0-02-unix.tar.gz 创建安装目录 mkdir -p /opt/n ...

  2. Linux安装配置PHPmyadmin

    进官网下载zip安装包 wget https://files.phpmyadmin.net/phpMyAdmin/5.0.1/phpMyAdmin-5.0.1-all-languages.zip 安装 ...

  3. MacOS下如何优雅的使用冰蝎

    因为冰蝎也是使用 JAVA 写的跨平台应用程序,我们可以借助 macOS 自带的 自动操作 automator.app 来创建一个应用程序. 前言: 冰蝎是一种新型的Webshell连接工具,在日常的 ...

  4. java循环语句for与无限循环

    一 for循环 for循环语句是最常用的循环语句,一般用在循环次数已知的情况下. 格式: for(初始化表达式; 循环条件; 操作表达式){ 执行语句 ……… } 循环流程: for(① ; ② ; ...

  5. C#LeetCode刷题之#709-转换成小写字母(To Lower Case)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3965 访问. 实现函数 ToLowerCase(),该函数接收一 ...

  6. Typescript node starter 3. App Router Controller

    Request request对象表示HTTP请求,并具有请求query字符串.参数.body.HTTP headers等的属性.除了添加新的属性和方法外,还包含原型的属性和方法. 随着系列文章的发布 ...

  7. 远程控制(远控Bin)

    一.概念 控制端:运行在攻击者的电脑中,负责控制其他肉鸡: 被控制端:需要去生成,运行在肉鸡上,木马病毒 二.使用远控Bin工具实现内网远程控制 Step1:打开Kill.exe,点击系统设置,修改监 ...

  8. QPS过万,redis大量连接超时怎么解决?

    7月2号10点后,刚好某个负责的服务发生大量的redis连接超时的异常(redis.clients.jedis.exceptions.JedisConnectionException),由于本身的数据 ...

  9. K8s 1.18.6版本基于 ingress-nginx 实现金丝雀发布(灰度发布)

    K8s 1.18.6版本基于 ingress-nginx 实现金丝雀发布(灰度发布) 环境 软件 版本 kubernetes v1.18.6 nginx-ingress-controller 0.32 ...

  10. python编程中的并发------多进程multiprocessing

    任务例子:喝水.吃饭动作需要耗时1S 单任务:(耗时20s) for i in range(10): print('a正在喝水') time.sleep(1) print('a正在吃饭') time. ...