Can't use the order in this choice?

I have this request.

SELECT ClassId, Sum(TeachersCount) as NumCount FROM ClassSubject GROUP BY ClassId ORDER BY NumCount 

but when I started this, access pops up in the field asking me about the value of NumCount? But this is not a parameter, it is ... well, this is the sum of the teachers who can teach this class, and it should be calculated. So why is the query asking me for a value ( NumCount's )?

I want to count the number of teachers in the class and streamline this by increasing the number of teachers, I think my request is, but why does he ask me about the value of NumCount ? One more thing, if I delete this ORDER BY , it works fine without asking me the NumCount value? So what is the problem?

+6
source share
1 answer

You need:

 SELECT ClassId, Sum(TeachersCount) as NumCount FROM ClassSubject GROUP BY ClassId ORDER BY Sum(TeachersCount) 

You can also ORDER by serial number, in this case 2:

 ORDER BY 2 
+6
source

Source: https://habr.com/ru/post/917349/


All Articles