SQL语句的问题,想不明白啊!

来源:百度知道 编辑:UC知道 时间:2024/05/30 09:59:57
现有一张表sc为学生选课表,有以下字段:s#,c#,grade分别为:学生学号,课程编号和成绩,我要想按学号分组然后选出每组中第一条记录的SQL语句如下:
select * from sc a
where grade=(select top 1 grade from sc where s#=a.s#)

这个语句我看不懂,高手指点一下啊,详细一点!在此谢过~
应该是这样才对:select * from sc a
where grade=(select top 1 grade from sc where s#=a.s#)
and c#=(select top 1 c# from sc where s#=a.s#)
如果c#或grade有在分组中一个相同就不行了

子查询引用主查询..
select * from sc a --这里不用解释吧.
where grade--当分数为
=(select top 1 grade --显示最高的分数
from sc
where s#=a.s#)--子查询的条件.课程号为主查询的课程号
---------------

那个a 是干什么的啊?是 别名? 什么啊都是 s#=a.s#是什么意思啊?