我有以下SQL查询:
select u.user_name, sum(r.goals) total_goals, sum(r.goals)/(2 * count(1)) avg_goals
from (select community_id, player1_id id, player1_goals goals
from results union all select community_id, player2_id, player2_goals from results) r
inner join users u on r.id = u.id
where r.community_id = 16 group by r.id, u.user_name
ORDER BY avg_goals DESC
产生如下结果
"avg_goals" , "1.2500"
(我只对此实例的此列感兴趣)
如何将结果中的小数位数限制为2?因此输出将是1.25
而不是1.2500
答案 0 :(得分:3)
您可以使用ROUND(col, 2)
cd /path/to/glib/source/bld
make clean
../configure --prefix=/mingw
make
make install
正如@scaisEdge所说,如果你只想截断其余的数字,你也可以使用truncate(col,2)。
答案 1 :(得分:0)
你应该使用TRUNCATE,例如:
SELECT TRUNCATE(1.2500,2) from dual ;
SELECT TRUNCATE(round(sum(r.goals)/(2 * count(1)),2), 2) .....