How to do division in SQL query between two column

enter image description here In the above image I have 4 column and I am trying to get the average value of criticality and Priority by dividing it by the totalNumber. But for some reason my query is not working and I also trying to just get one decimal place after the division.

My sql query:

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

Answer

Try to use cast(round(criticality/totalNumber,1) as numeric(36,1)) for one decimal place after division.

$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'";

Leave a Reply

Your email address will not be published. Required fields are marked *