如何在两列之间的SQL查询中进行除法

时间:2018-02-13 04:21:06

标签: mysql sql

enter image description here 在上面的图像中,我有4列,我试图通过将它除以totalNumber来获得临界值和优先级的平均值。但由于某种原因我的查询不起作用,我也试图在除法后得到一个小数位

我的SQL查询:

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

1 个答案:

答案 0 :(得分:1)

尝试在分割后将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'";