开发者

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

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


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.


use the ROUND function to wrap the AVG calculation...


Maybe you are looking for this :

SELECT grade.GStudNo, CAST(AVG(grade.Grade) AS DECIMAL(10,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

this get only 2 decimals

CAST(AVG(grade.Grade) AS DECIMAL(10,2))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜