sql查询出各科成绩最好的学生信息

前端之家收集整理的这篇文章主要介绍了sql查询出各科成绩最好的学生信息前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.相关数据表 score
<IMG src="https:https://files.jb51.cc/file_images/article/201405/20140515161550.jpeg?2014415161612"&gt;
[User]表
<IMG src="https:https://files.jb51.cc/file_images/article/201405/20140515161635.jpeg?2014415161655"&gt;
sql语句如下:
<div class="codetitle"><a style="CURSOR: pointer" data="26496" class="copybut" id="copybut26496" onclick="doCopy('code26496')"> 代码如下:

<div class="codebody" id="code26496">
--查询出各科成绩最好的学生信息
--自连接
--SELECT TOP 1 * FROM score B WHERE B.scoreName = '数学' ORDER BY B.score DESC SELECT A.ID,U.Name,A.scoreName,A.score
FROM score A,[User]U
WHERE UID IN (SELECT TOP 1 UID
FROM score B
WHERE B.scoreName = A.scoreName
ORDER BY B.score DESC) AND A.UID=U.ID
ORDER BY A.scoreName,A.score DESC

查询结果如下图:
<IMG src="https:https://files.jb51.cc/file_images/article/201405/20140515161723.jpeg?2014415161747"&gt;

原文链接:https://www.f2er.com/mssql/63271.html

猜你在找的MsSQL相关文章