I have table named ‘marks’ which stores marks of students.
id name social math science 2 Max Ruin 85 85 56 3 Arnold 75 40 170 4 Krish 60 70 50 5 John 60 90 80
I want to get the name of student who has highest total mark.
I tried query like this
SELECT name, (social + math +science) AS total_mark FROM marks where total_mark = max(total_mark );
But this is not working. Can anyone please help ?
Advertisement
Answer
get the max()
total first then use a subquery
select * from marks where (social+math+science) = (select max(social+math+science) from marks);