有哪位大神能说说嘛?关于SQL

要统计每个学生的总学分是对什么分组?有哪位大神能说说嘛?关于SQL
select student.sno,COUNT(ccredit) from student,sc,course
where student.sno=sc.sno and sc.cno=course.cno
group by sname
系统提示消息 8120,级别 16,状态 1,第 1 行
选择列表中的列 'student.sno' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。
要怎么改呢?

对学生,分组之后求和

今年学了一点,学的比较浅显,SQL学的主要是其语言和SQL Server的使用,就是创建表格,查询,数据保护,还有一些基础的定义

sql server的存储过程学好了,sql就ok了

以每个学生的学号求其总分后以学号分组

分析一下要对什么样的结果集合进行分组求和才能得出答案呢?
如下面的结果集合

sno sname coursenm ccredit

学生的名字可能重名,所以使用sname分组是不对的。要采用学号进行分组。

所以先得到上面的结果集合,然后再对它进行分组count

1--得到结果集合
select student.sno,student.sname,course.coursenm,sc.ccredit from student,sc,course
where student.sno=sc.sno and sc.cno=course.cno

2--用上面的结果作为查询视图再进行

select inf.sno,count(inf.ccredit) from (
select student.sno,student.sname,course.coursenm,sc.ccredit from student,sc,course
where student.sno=sc.sno and sc.cno=course.cno
) as inf
group by inf.sno

你的这个代码之所以报错:

select student.sno,COUNT(ccredit) from student,sc,course
where student.sno=sc.sno and sc.cno=course.cno
group by sname

主要的就在于 你按照sname分组,但是你的select里出现了student.sno字段,sql规定在当group by的时候,select的列必须是group by的列或者 是使用了聚合函数,
如:count,max,min,sum等,

所以你的代码要改成:

select student.sno,COUNT(ccredit) from student,sc,course
where student.sno=sc.sno and sc.cno=course.cno
group by student.sno,sname

楼上说的对,使用group的时候,select的项目要出现在group中。
另外,使用count是不对的。
count是统计个数。
要求总学分应该使用sum集计函数进行求和才对