--不分班按学生成绩排名
select *,ROW_NUMBER() over(order by Score desc) as Sequence from Student

id          Grade       Score       Sequence
----------- ----------- ----------- --------------------
8           3           90          1
1           1           88          2
6           2           80          3
10          3           80          4
3           1           75          5
9           3           70          6
5           2           70          7
2           1           66          8
7           2           60          9
4           2           30          10

(10 行受影响)

--分班后按学生成绩排名
select *,row_number() over(partition by Grade order by Score desc) as Sequence from Student

id          Grade       Score       Sequence
----------- ----------- ----------- --------------------
1           1           88          1
3           1           75          2
2           1           66          3
6           2           80          1
5           2           70          2
7           2           60          3
4           2           30          4
8           3           90          1
10          3           80          2
9           3           70          3

(10 行受影响)

sql partition by的更多相关文章

  1. SQL partition (小组排序)

    很多时候,我们在SQL中进行数据去重(distinct) 结果发现有2条一样ID,或者name的数据,我们想要最接近的那条数据. 直接看看题目: 原表 select ID,Title,PRICE fr ...

  2. sql partition by 的使用

    select a.bs_sn, a.bs_bd_no, a.bs_bk_code, a.bs_kind_no, a.bs_flag, b.det_flag, c.bp_in_no, c.bp_name ...

  3. SQL partition by的用法

    今天群里看到一个问题,在这里概述下:查询出不同分类下的最新记录.一看这不是很简单的么,要分类那就用Group By; 要最新记录就用Order By呗.然后在自己的表中试着做出来: 首先呢我把表中的数 ...

  4. SQL PARTITION BY:列值改变时重置计数

    现有数据如下: 需求:以科目为单位 对分数进行排序 SELECT *, ROW_NUMBER() OVER (PARTITION BY 科目 ORDER BY 分数 DESC) AS NUM FROM ...

  5. Azure SQL Database (27) 创建Table Partition

    <Windows Azure Platform 系列文章目录> 昨天客户正好提到这个问题,现在记录一下. 我们在使用传统的SQL Server,会使用Table Partition,这个功 ...

  6. SQL常用函数总结

    SQL常用函数总结 这是我在项目开发中使用db2数据库写存储过程的时候经常用到的sql函数.希望对大家有所帮助: sql cast函数 (1).CAST()函数的参数是一个表达式,它包括用AS关键字分 ...

  7. hive 批量添加,删除分区

    一.批量添加分区:   use bigdata; alter table siebel_member add if not exists partition(dt='20180401') locati ...

  8. sql 分组取最新的数据sqlserver巧用row_number和partition by分组取top数据

    SQL Server 2005后之后,引入了row_number()函数,row_number()函数的分组排序功能使这种操作变得非常简单 分组取TOP数据是T-SQL中的常用查询, 如学生信息管理系 ...

  9. SQL 语句-partition by

    /****** ******/ 初始化数据 create table employee (empid int ,deptid int ,salary decimal(10,2)) insert int ...

随机推荐

  1. python简单实用gunicorn部署

    linux 安装 pyuthon 安装   pip install gunicorn manage.py 文件 from app import create_app app = create_app( ...

  2. Centos7之Nginx

    1.安装 下载RPM: wget http://nginx.org/download/nginx-1.16.0.tar.gz 解压:tar -zxf nginx-1.16.0.tar.gz 安装: c ...

  3. php微信红包算法

    微信红包算法.php /**生成红包的函数*/ function getRandMoney($totalMoney, $totalPeople=2, $miniMoney=1){ $randRemai ...

  4. python 斗图图片爬虫

    捣鼓了三小时,有一些小Bug,望大佬指导 废话不说,直接上代码: #!/usr/bin/python3 # -*- coding:UTF-8 -*- import os,re,requests fro ...

  5. Django API 为 D3 提供数据

    在工作中见过有的人即便使用了Django,依然还在采取json或geojson的文件形式为页面提供数据,相当于嵌入数据而非加载.下面是个简单有效的例子: 先从 model.py 开始 # models ...

  6. P3387 【模板】缩点

    题目背景 缩点+DP 题目描述 给定一个n个点m条边有向图,每个点有一个权值,求一条路径,使路径经过的点权值之和最大.你只需要求出这个权值和. 允许多次经过一条边或者一个点,但是,重复经过的点,权值只 ...

  7. 9、JS对象 知识总结

    1.对象 <!DOCTYPE html> <html> <body> <script> <!-- 新建对象 --> person=new O ...

  8. 47.关于gradle的解疑

    Short Answer Gradle is a build system. Long Answer Before Android Studio you were using Eclipse for ...

  9. 【Gas Station】cpp

    题目: There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. ...

  10. python re 模块小结

    前言: 本人环境windows 7 64位,python2.7 re是什么: regular expression缩写,意为正则表达式,是python的众多模块之一 re用途: 从文本中有选择的批量抽 ...