学生表:

  1. create table hy_student(
  2. id number(4,0) primary key,
  3. name nvarchar2(20) not null,
  4. score number(3,0) not null)

充值:

  1. insert into hy_student
  2. select rownum,dbms_random.string('*',dbms_random.value(1,20)),dbms_random.value(0,100)
  3. from dual
  4. connect by level<201
  5. order by dbms_random.random

第一步把学生按成绩逆序排列:

  1. select * from hy_student order by score desc

第二步给加伪列:

  1. select rownum as rn,a.* from (select * from hy_student order by score desc) a

最后就可以检出前10%的精英了:

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

  1. create table hy_student(
  2. id number(4,0) primary key,
  3. name nvarchar2(20) not null,
  4. score number(3,0) not null)
  5.  
  6. insert into hy_student
  7. select rownum,dbms_random.string('*',dbms_random.value(1,20)),dbms_random.value(0,100)
  8. from dual
  9. connect by level<201
  10. order by dbms_random.random
  11.  
  12. commit;
  13.  
  14. select * from hy_student order by score desc
  15.  
  16. select rownum as rn,a.* from (select * from hy_student order by score desc) a
  17.  
  18. 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. 解决SpringBoot项目中Thymeleaf模板的中文乱码问题

    1.使用IDEA创建SpringBoot项目 package com.example.demo; import org.springframework.boot.SpringApplication; ...

  2. 新司机的致胜法宝,使用ApexSql Log2018快速恢复数据库被删除的数据

    作为开发人员,误操作数据delete.update.insert是最正常不过的了,比如: 删除忘记加where条件: 查询为了图方便按了F5,但是数据里面夹杂着delete语句. 不管是打着后发动机声 ...

  3. Bytom Dapp 开发笔记(二):开发流程

    简介 这章的内容详细分析一下涉及智能合约Dapp的整个开发流程,注意是涉及只能合约,如果你只要一些基本转BTM功能没有太大意义,本内容补充一下官方提供的 比原链DAPP开发流程,详细实践过好踩到的一些 ...

  4. Vue 自定义VueRouter-简版

    主要是思路,自己定义组件的时候可以借鉴 Vue-router的 类图 name options: ==> 记录构造函数中传入的对象,在 new VueRouter的时候传了一个对象( route ...

  5. notepad++ 设置支持golang语法高亮

    see https://stackoverflow.com/questions/27747457/golang-plugin-on-notepad

  6. flask_restful实现文件下载功能

    环境:前后端完全分离,后端flask_restful,前端vue from flask_restful import reqparse, Resource from flask import send ...

  7. ExcelWeb脚本助手,自定义脚本,批量操作Excel与网页

    ExcelWeb脚本助手,是一款可以自定义脚本操控Excel和浏览器的工具.提供了简单实用的Excel与Browser的API调用,通过自建脚本或自建项目,随意定制. 可以非常方便的根据Excel中的 ...

  8. XXE漏洞学习笔记

    XXE 参考文章 名称 地址 一篇文章带你深入理解漏洞之 XXE 漏洞 https://xz.aliyun.com/t/3357 Web Hacking 101 https://wizardforce ...

  9. mysql无法远程连接问题(ERROR 1045 (28000): Access denied for user 'root')

    mysql版本 : 8.0.21 使用mysql 作为nextcloud的数据库.之前使用挺正常的,因为被黑客勒索过一次,重新启动了一个mysql的docker镜像. 结果数据库配置老是失败,next ...

  10. VMware Workstation 15 Pro安装带图形化界面的CentOS7

    1.双击打开“VMware Workstation”,然后选择“创建新的虚拟机” 2.在安装向导中,选择“稍后安装操作系统”,然后点击“下一步”继续安装 3.在“客户机操作系统”中选择“Linux(L ...