I have this query which is working just fine:
SELECT [Exam Category]
,[Student No_]
,Gender
,Description
,Stage
FROM [MYDB $Course Registration]
inner join [MYDB $Student]
ON [Student No_] = No_
inner join [MYDB $Programme]
ON Code = Programme
where Gender != 0
order by [Exam Category] desc
,[Student No_]
,Stage
However, i would like to group by [Exam Category]:
SELECT [Exam Category]
,[Student No_]
,Gender
,Description
,Stage
FROM [MYDB $Course Registration]
inner join [MYDB $Customer]
ON [Student No_] = No_
inner join [MYDB $Programme]
ON Code = Programme
where Gender != 0
group by [Exam Category]
order by Stage
,[Student No_]
but it brings up the error
Msg 8120, Level 16, State 1, Line 9 Column 'MYDB $Course Registration.Student No_' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
any help?
codeSELECT COUNT (DISTINCT [Student No_]) FROM [MYDB $Course Registration] inner join [MYDB $Customer] ON [Student No_] = No_ inner join [MYDB $Programme] ON Code=Programme WHERE Semester = 'SEM1 16/17' AND Gender = '1' AND Programme = 'HT 100' AND Stage = 'Y2S1'code