zoukankan      html  css  js  c++  java
  • sql server row_number分页排序

    --1.创建测试表
    create table #score
    (
    name varchar(20),
    subject varchar(20),
    score int
    )
    --2.插入测试数据
    insert into #score(name,subject,score) values('张三','语文',98)
    insert into #score(name,subject,score) values('张三','数学',80)
    insert into #score(name,subject,score) values('张三','英语',90)
    insert into #score(name,subject,score) values('李四','语文',88)
    insert into #score(name,subject,score) values('李四','数学',86)
    insert into #score(name,subject,score) values('李四','英语',88)
    insert into #score(name,subject,score) values('李明','语文',60)
    insert into #score(name,subject,score) values('李明','数学',86)
    insert into #score(name,subject,score) values('李明','英语',88)
    insert into #score(name,subject,score) values('林风','语文',74)
    insert into #score(name,subject,score) values('林风','数学',99)
    insert into #score(name,subject,score) values('林风','英语',59)
    insert into #score(name,subject,score) values('严明','英语',96)
    --3.取每个学科的前3名数据
    select * from
    (
    select subject,name,score,ROW_NUMBER() over(PARTITION by subject order by score desc) as num from #score
    ) T where T.num <= 3 order by subject
    --4.删除临时表
    truncate table #score
    drop table #score

  • 相关阅读:
    char类型细节
    Hibernate面试题
    线程
    IO流
    集合
    链表相关的一点东西
    正则表达式学习
    python中的变量域问题
    python的输出和输入形式
    python mutable 和 immutable
  • 原文地址:https://www.cnblogs.com/weixin18/p/12809032.html
Copyright © 2011-2022 走看看