gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 10:23:34 25 4
gpt4 key购买 nike

enter image description here在上图中,我有 4 列,我试图通过将其除以总数量来获得关键性和优先级的平均值。但由于某种原因,我的查询不起作用,并且我还尝试在除法后仅获取一位小数。

我的sql查询:

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

最佳答案

尝试使用 cast(round(riticity/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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com