I want to have a switch case in my SQL query such that when the group by does not group any element i dont want to aggregate otherwise I want to. Is that possible.
my query is something like this:
select count(1),AVG(student_mark) ,case when Count(1)=1 then student_subjectid else null end from Students
group by student_id
i get this error Column 'student_subjectid' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Thanks in advance..
EDITremark. Otherwise you should remove or replace the original error message, because it's confusing now.Column 'Student_mark' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.I understand it is related to your query's previous version. Your updated script wouldn't produce this error.