-1

I just run this query:

select 
    sc.Studentid as [Student ID], StudentName, semester, 
    sum(c.credit) as Creditsemester,
    cast(sum(w.[Weight]*c.credit) / sum(c.credit) as decimal(5, 2)) as [Semester GPA],
    (select sum(c.credit) from StudentScore) as cumulativecredit
from 
    StudentScore sc 
join 
    Student s on s.Studentid = sc.Studentid
join 
    Course c on sc.CourseID = c.CourseID
join 
    [weight] w on sc.Grade = w.GRADE
group by 
    sc.semester, sc.Studentid, s.StudentName

and I get this error:

Msg 512, Level 16, State 1, Line 163
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

Any ides for solving this?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

This is malformed:

  (select sum(c.credit) from StudentScore) as cumullativecredit

I'm not sure what you intend, but you have a reference to the outer query here. Because the outer query is an aggregation query, the sum() refers to the outer query, so this is not an aggregation query.

It is quite unclear what you want to do. If you referred to the table in the subquery, this would not generate that error:

  (select sum(ss.credit) from StudentScore ss) as cumulativecredit
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786