mysql - 如何在两列之间的SQL查询中进行除法-LMLPHP
在上面的图片中,我有4列,我试图通过对totalNumber进行除法来获得临界度和优先级的平均值。 。

我的SQL查询:

$command1 = "UPDATE rating SET criticality = criticality + '$c' / totalNumber , Priority = Priority + '$p' / totalNumber, totalNumber = totalNumber + '$counter' WHERE no = '$id'";

最佳答案

除法后,尝试将cast(round(criticality/totalNumber,1) as numeric(36,1))用于小数点后一位。

$command1 = "UPDATE rating SET criticality = cast(round(criticality/totalNumber,1) as numeric(36,1)) , Priority = cast(round(Priority /totalNumber,1) as numeric(36,1)) , totalNumber = totalNumber + '$counter' WHERE no = '$id'";

关于mysql - 如何在两列之间的SQL查询中进行除法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48759392/

10-08 22:43