天天看点

mysql限制小数位_mysql – 在sql中设置sum的小数位

我有一个数据库,我用于辩论比赛我试图排名积分,看看哪些学校将在学期末的决赛中发挥作用.

我有这个工作如下所示但是我无法绕过ptc字段,它目前返回最多4个小数位,例如0.6667如果他们赢得了3个辩论中的2个.

SELECT t.id,t.name AS name,SUM(t.id = d.winnerid) AS w,SUM(t.id != d.winnerid) AS l,SUM(t.id = d.winnerid)/(SUM(t.id = d.winnerid)+SUM(t.id != d.winnerid)) AS ptc

FROM debates AS d

JOIN teams AS t ON t.id IN (d.hostid,d.visitid)

WHERE d.visitid != -1

AND d.debatedate < CURDATE()

GROUP BY t.id

ORDER BY ptc DESC

我相信我必须在这里使用十进制(2,2)但是我无法正确使用语法我尝试了一些不同的东西,比如

SUM(t.id = d.winnerid)/(SUM(t.id = d.winnerid)+SUM(t.id != d.winnerid)) AS ptc decimal (2,2)

如果需要,我很乐意提供有关表格的更多信息,但我不认为这是必需的?