Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make the decimal places of AVG function in sql limit to 2 only?

Tags:

I want to limit the decimal of the average to 2..

SELECT grade.GStudNo, AVG(grade.Grade) AS Average, students.LName, students.FName, students.MName, students.Course
FROM students INNER JOIN grade ON students.StudNo = grade.GStudNo
WHERE GSem = '$sem' AND GYear = '$year'
GROUP BY grade.GStudNo
ORDER BY Average ASC LIMIT 3
like image 728
PiDO Avatar asked Mar 15 '11 18:03

PiDO


1 Answers

SELECT grade.GStudNo, ROUND( AVG(grade.Grade),2 ) AS Average, students.LName, students.FName, students.MName, students.Course
FROM students INNER JOIN grade ON students.StudNo = grade.GStudNo
WHERE GSem = '$sem' AND GYear = '$year'
GROUP BY grade.GStudNo
ORDER BY Average ASC LIMIT 3

Would round it to two places.

like image 59
DhruvPathak Avatar answered Oct 02 '22 14:10

DhruvPathak