有一道SQL笔试题是这样子的:

已知表信息如下:

Department(depID, depName),depID 系编号,DepName系名

Student(stuID, name, depID) 学生编号,姓名,系编号

Score(stuID, category, score) 学生编码,科目,成绩

找出每一个系的最高分,并且按系编号,学生编号升序排列,要求顺序输出以下信息:

系编号,系名,学生编号,姓名,总分

USE [test]
GO
/****** Object: Table [dbo].[Score] Script Date: 05/11/2015 23:16:23 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Score](
[stuID] [int] NOT NULL,
[category] [varchar](50) NOT NULL,
[score] [int] NOT NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (1, N'英语', 80)
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (2, N'数学', 80)
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (1, N'数学', 70)
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (2, N'英语', 89)
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (3, N'英语', 81)
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (3, N'数学', 71)
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (4, N'数学', 91)
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (4, N'英语', 61)
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (5, N'英语', 91)
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (6, N'英语', 89)
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (7, N'英语', 77)
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (8, N'英语', 97)
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (9, N'英语', 57)
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (5, N'数学', 87)
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (6, N'数学', 89)
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (7, N'数学', 80)
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (8, N'数学', 81)
INSERT [dbo].[Score] ([stuID], [category], [score]) VALUES (9, N'数学', 84)
/****** Object: Table [dbo].[Department] Script Date: 05/11/2015 23:16:23 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Department](
[depID] [int] IDENTITY(1,1) NOT NULL,
[depName] [varchar](50) NOT NULL,
PRIMARY KEY CLUSTERED
(
[depID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[Department] ON
INSERT [dbo].[Department] ([depID], [depName]) VALUES (1, N'计算机')
INSERT [dbo].[Department] ([depID], [depName]) VALUES (2, N'生物')
INSERT [dbo].[Department] ([depID], [depName]) VALUES (3, N'数学')
SET IDENTITY_INSERT [dbo].[Department] OFF
/****** Object: Table [dbo].[Student] Script Date: 05/11/2015 23:16:23 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Student](
[stuID] [int] IDENTITY(1,1) NOT NULL,
[stuName] [varchar](50) NOT NULL,
[deptID] [int] NOT NULL,
PRIMARY KEY CLUSTERED
(
[stuID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[Student] ON
INSERT [dbo].[Student] ([stuID], [stuName], [deptID]) VALUES (1, N'计算机张三', 1)
INSERT [dbo].[Student] ([stuID], [stuName], [deptID]) VALUES (2, N'计算机李四', 1)
INSERT [dbo].[Student] ([stuID], [stuName], [deptID]) VALUES (3, N'计算机王五', 1)
INSERT [dbo].[Student] ([stuID], [stuName], [deptID]) VALUES (4, N'生物amy', 2)
INSERT [dbo].[Student] ([stuID], [stuName], [deptID]) VALUES (5, N'生物kity', 2)
INSERT [dbo].[Student] ([stuID], [stuName], [deptID]) VALUES (6, N'生物lucky', 2)
INSERT [dbo].[Student] ([stuID], [stuName], [deptID]) VALUES (7, N'数学_yiming', 3)
INSERT [dbo].[Student] ([stuID], [stuName], [deptID]) VALUES (8, N'数学_haoxue', 3)
INSERT [dbo].[Student] ([stuID], [stuName], [deptID]) VALUES (9, N'数学_wuyong', 3)
SET IDENTITY_INSERT [dbo].[Student] OFF
/****** Object: Default [DF__Departmen__depNa__5441852A] Script Date: 05/11/2015 23:16:23 ******/
ALTER TABLE [dbo].[Department] ADD DEFAULT ('') FOR [depName]
GO
/****** Object: Default [DF__Score__category__5EBF139D] Script Date: 05/11/2015 23:16:23 ******/
ALTER TABLE [dbo].[Score] ADD DEFAULT ('') FOR [category]
GO
/****** Object: Default [DF__Score__score__5FB337D6] Script Date: 05/11/2015 23:16:23 ******/
ALTER TABLE [dbo].[Score] ADD DEFAULT ((0)) FOR [score]
GO
/****** Object: Default [DF__Student__stuName__59063A47] Script Date: 05/11/2015 23:16:23 ******/
ALTER TABLE [dbo].[Student] ADD DEFAULT ('') FOR [stuName]
GO
/****** Object: ForeignKey [FK__Student__deptID__59FA5E80] Script Date: 05/11/2015 23:16:23 ******/
ALTER TABLE [dbo].[Student] WITH CHECK ADD FOREIGN KEY([deptID])
REFERENCES [dbo].[Department] ([depID])
GO

SQL查询语句:

with t1 as
(
select b.stuID,SUM(a.score) as score from dbo.Score a
left join dbo.Student b on a.stuID = b.stuID
group by b.stuID
), t2 as
(
select a.stuID,a.stuName,a.deptID,b.depName from dbo.Student a
left join Department b on a.deptID = b.depID
), t3 as
(
select rank() OVER(partition by deptID order by score desc) as RowId,
t2.stuID,t2.stuName,t2.deptID,t2.depName,t1.score from t1
left join t2 on t1.stuID = t2.stuID
) select stuID,stuName,deptID,depName,score from t3 where RowId = 1

查询结果:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWgAAACGCAYAAADw3BCTAAAgAElEQVR4Ae1dfXAcxZV/yt1hsAk4RajLx+VL1ipGXsgfUJSQ60KOgInkXOL4KFUqV1eqSkBKsIkVwCTUcfdHyncEGyg5mCukQK78xyWUzsECYgk4MMcfVrlyfFTsRTaWRHEUR1JFSPiywQZb129m3u7bVk/v7OzOTs/u66pVd79+3f3697qfentm+7W98cYbC6P3/ge0Yhi6+u9bcdgyZkFAEMgIAn9Oct50w7WUbIl46x3/1hLjlEEKAoJAdhEoGujsDiG+5M36zUG+GcSfE1JTEHAJgZY20DcMD7mki7rIcsfIaF3akUYEAUEgfQQiG+ihsWes0j4TUvz06IXWemkWHjt2bFH3zz77rEd76623FpX98Y9vwfr1X1tEd4WwdOlSV0QROQQBQaAOCEQ20NjXhRcyY6sMMrfJvIjkeibMahNDELe1tcHCwkIZ1UQrY0go88ILZ8LgIBtn0M9rr70Gt+zeDesT6leaFQQEAUFAR6AqA20yuFYbzC243nPMPBruSkE39mH8lfhwFz37/lle9SMvneb9R1r4Zvk/krC206BXGk8aMkmfgoAgEB+ByAYa95R8Z/n000/DRRddVOz5qaeegksvvdTLHz9+HHbuLMDYM2Mqbz8T5Ttl3fjyPDc+PM3rY+e8jieM5Q9vR2c7fPgwHD161NvZzy7k4O3n5jwWWx29jSj55cuXg3rV0coahcfagBQKAoJAJhGIbKD10aHx4oHObNE44wfDaacd5CyL0ty48jQy6nleWTfCep7z2tJhxnZMfS34+Kuvwu9+9wlYsuQF1cQLKvZbCqtj6wfLPvKRj8Cf/vQnj42nkUBtcjqmeUAjrQdqT6dLXhAQBJoDgcgGesmSw3D48DJ45513vJ0lDh93zTyMqQeJH//4q4AP0wBW8qLQNBlXMlKhjKyA8+qGnNpj7KHJU6dO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By0z17TT1dD03DqVdrnISa6+gDPoRUH7TQfkR8486rPzoRovt0NH/Yd2PIjpgbb+bbs04NKRjN/TOJUsvLS6vasPebqAXtb0CNux9D44e8z8HtnZD99bn4YmNjXV5hT4Jp8f3BMbDPZdXZFARPp5eBGdAwIWtf7BIp5EBCGsnnM7Ob0NcY+E/vel8p/LHUjr68I861Gm0zb1WT+BwFjv3duqlV63C5alc4h1tlA7LYc/4NOQdP4TmuubpsNGG6TeMHtaOu3RxeVWrbqx3cdAZtK2TU2ncGe242xxcYLhAyaBimoJeRvTkYs01FnakjkI811g7R2A1Hk8EtNl9Odi+OucdbXguxHonYaItB6uV58Od6oy6snutHs+Flu1UBLuKEvBoY9J74Olze+6u6tFwlM5j8ui6TVfvMQdRz2ri8qpmNMXlVQwIo14gQwuUDDV2RYab4rDuK5WH1csKPSqGLo0nqszNpPeoY05LT67LVysu9iOOBN7QQGNV6VProNKujwuUDCztqlAmomGa0zFPgepSfnGMv9gynVnX52hhcX9CiYoA6Y7mN+Yx1EfvUaUQvmZCoMIRh29Mm2nAjRgLLlAeKE8xlel5pJtoxO/HyqO5an+0nCg5BxDQdUd5iklEPY90E434JW5dBKwGWlxete7EkJELAoJA+ghYDbS4vEpfQSKBICAItC4CVgMtLq/CJwY+nJBQGwJZxDCLMtemJbddXrnsealW3LF+qIFu9oHXAzxpQxAQBASBJBGwv8WRZM/StiAgCAgCgoAVATHQVnikUBAQBASB9BAQA50e9tKzICAICAJWBMRAW+GRQkFAEBAE0kNADHR62EvPgoAgIAhYERADbYVHCgUBQUAQSA8BMdDpYS89CwKCgCBgRUAMtBUeKRQEBAFBID0ExECnh730LAgIAoKAFQEx0FZ4pFAQEAQEgfQQEAOdHvbSsyAgCAgCVgTEQFvhkUJBQBAQBNJDQAx0ethLz4KAICAIWBEQA22FRwoFAUFAEEgPgf8HPWeq9DlJNEgAAAAASUVORK5CYII=" alt="" />

与row_rumber不同,rank考虑到了over子句中排序字段值相同的情况。如果使用row_number替换rank,则deptID为2的记录只会有1条。

SQL技巧之排名统计的更多相关文章

  1. 用sql语句写排名

    使用SQL语句求排名 表jh03有下列数据: name score aa 99 bb 56 cc 56 dd 77 ee 78 ff 76 gg 78 ff 50 1. 名次生成方式1 , Score ...

  2. MySQL基础操作&&常用的SQL技巧&&SQL语句优化

    基础操作     一:MySQL基础操作         1:MySQL表复制             复制表结构 + 复制表数据             create table t3 like t ...

  3. SQL Server-深入剖析统计信息

    转自: http://www.cnblogs.com/zhijianliutang/p/4190669.html   概念理解 关于SQL Server中的统计信息,在联机丛书中是这样解释的 查询优化 ...

  4. SQL语句调优 - 统计信息的含义与作用及维护计算

    统计信息的含义与作用                                                                                          ...

  5. SQL Server里等待统计(Wait Statistics)介绍

    在今天的文章里我想详细谈下SQL Server里的统计等待(Wait Statistics),还有她们如何帮助你立即为什么你的SQL Server当前很慢.一提到性能调优,对我来说统计等待是SQL S ...

  6. SQL大数据操作统计

    SQL大数据操作统计 1:select count(*) from table的区别SELECT object_name(id) as TableName,indid,rows,rowcnt FROM ...

  7. C# Linq to sql 实现 group by 统计多字段 返回多字段

    Linq to sql 使用group by 统计多个字段,然后返回多个字段的值,话不多说,直接上例子: where u.fy_no == fy_no orderby u.we_no group u  ...

  8. mysql数据库优化课程---14、常用的sql技巧

    mysql数据库优化课程---14.常用的sql技巧 一.总结 一句话总结:其实就是sql中那些函数的使用 1.mysql中函数如何使用? 选择字段 其实就是作用域select的选择字段 3.转大写: ...

  9. SQL Server中排名函数row_number,rank,dense_rank,ntile详解

    SQL Server中排名函数row_number,rank,dense_rank,ntile详解 从SQL SERVER2005开始,SQL SERVER新增了四个排名函数,分别如下:1.row_n ...

随机推荐

  1. hdu 5455 Fang Fang 坑题

    Fang Fang Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5455 ...

  2. ios开发——实用技术OC-Swift篇&触摸与手势识别

    iOS开发学习之触摸事件和手势识别   iOS的输入事件 触摸事件 手势识别 手机摇晃 一.iOS的输入事件   触摸事件(滑动.点击) 运动事件(摇一摇.手机倾斜.行走),不需要人为参与的 远程控制 ...

  3. Mysql一些重要配置参数的学习与整理系列

    http://my.oschina.net/realfighter/blog?catalog=585558&temp=1467909771588

  4. node.js 针对不同的请求路径(url) 做出不同的响应

    边看这个边写的: http://wenku.baidu.com/link?url=C4yLe-TVH6060u_x4t34H3Ze8tjoL7HjJaKgH-TvHnEYl-T_gAMYwhmrCeM ...

  5. mysqldump 的一些使用参数

    备份数据库#mysqldump 数据库名 >数据库备份名 #mysqldump -A -u用户名 -p密码 数据库名>数据库备份名 #mysqldump -d -A --add-drop- ...

  6. linux高级命令组合

    ps -auxww | grep httpd 快速找到正在运行的apache服务安装目录 find / -path  'sina_app_v3*' 快速找到根目录下面的sina_app_v3目录 fi ...

  7. linux crt

    1.仿真  终端选linux  ANSI颜色[有颜色了] 使用颜色方案[颜色加深了] 2.外观  选传统的 ,utf-8 就不会乱码了

  8. Linux下Openssl的安装全过程

    第一章 1.下载地址:http://www.openssl.org/source/ 下一个新版本的OpenSSL,我下的版本是:openssl-1.0.0e.tar.gz 可以通过#wget http ...

  9. table tr分离并加圆角和阴影

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. yii2 ./yii command : No such file or directory

    git clone下来的yii2后台项目,由于需要执行 ./yii migrate命令.执行之后,提示 No such file or directory 我从同样为yii2 basic的./yii ...