问题描述
- 求助:SQL Server语句出错求改正!!
-
我写了一个SQL Server语句,内容如下:select C.courseID,C.courseName,C.teacherID,C.teacherName,Sum(e.Grade) As count from EvaluateTeacherGrade e,Course C,Grade G where e.courseID=G.courseID and C.courseID=G.courseID and G.studentID='0711001'and C.courseID='100000'
但是有提示错误:
消息 8120,级别 16,状态 1,第 1 行
选择列表中的列 'Course.courseID' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。
我该如何改正啊??
解决方案
SELECT C.COURSEID,
C.COURSENAME,
C.TEACHERID,
C.TEACHERNAME,
SUM(E.GRADE) AS COUNT
FROM EVALUATETEACHERGRADE E,
COURSE C,
GRADE G
WHERE E.COURSEID=G.COURSEID
AND C.COURSEID=G.COURSEID
AND G.STUDENTID='0711001'
AND C.COURSEID='100000'
GROUP BY C.COURSEID,
C.COURSENAME,
C.TEACHERID,
C.TEACHERNAME
解决方案二:
Course.courseID
->
Max(Course.courseID)
放在聚合函数中
解决方案三:
用left join吧
时间: 2025-01-12 16:01:50