sql获取每门课程成绩最好的学生信息

1.相关数据表

Score表

sql获取每门课程成绩最好的学生信息

[User]表

sql获取每门课程成绩最好的学生信息

SQL语句例如以下:

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

--自连接

--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

查询结果例如以下图:

sql获取每门课程成绩最好的学生信息

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2hlbnlibG9n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

上一篇:1293 - Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause


下一篇:Android listview addHeaderView 和 addFooterView 详解