Reputation: 59
I was trying to execute the following command:
SELECT name,sum(mark)
FROM students
group by name order by mark
but I get the error.
Column "students.mark" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.
I am unable to understand the error.
Upvotes: 0
Views: 79
Reputation: 803
Try using this
SELECT name,sum(mark) FROM students group by name order by sum(mark)
Hope this helps
Upvotes: 3
Reputation: 2520
This should work for you,
SELECT name,sum(mark) FROM students group by name order by sum(mark)
You need to specify sum
aggregate in orderby
Upvotes: 0
Reputation: 93754
Move the SUM
aggregate to Order by
SELECT name,sum(mark) FROM students group by name order by sum(mark)
or use Alias name
SELECT name,sum(mark) as Mark FROM students group by name order by mark
Upvotes: 3