gpt4 book ai didi

mysql-为什么这两个查询返回不同的结果

转载 作者:行者123 更新时间:2023-11-30 00:14:46 25 4
gpt4 key购买 nike

由于某种原因,这两个 mysql 查询(我认为本质上是相同的,但格式不同)返回了不同的总和结果,我不完全确定为什么。

查询1(返回正确值)

SELECT sum((getRankint(cs_times.mapid, 1123, 0, 0))) AS rankval
FROM cs_times
INNER JOIN cs_maps ON cs_times.mapid = cs_maps.mapid
WHERE stage =0
AND TYPE =0
AND active =1
AND playerid =1123
AND getRankint(
cs_times.mapid, 1123, 0, 0
) <11

查询2

SELECT @rankval := getRankint(cs_times.mapid, 1123, 0, 0) AS rankval, 
sum(@rankval)
FROM cs_times
INNER JOIN cs_maps ON cs_times.mapid = cs_maps.mapid
WHERE stage =0
AND TYPE =0
AND active =1
AND playerid =1123
AND getRankint(
cs_times.mapid, 1123, 0, 0
) < 11

如果我在没有求和函数的情况下并排比较表格,它们的结果完全相同。然而总值(value)却有所不同。知道是什么原因造成的吗?谢谢。

(查询的 where 部分还有一个多余的函数调用,有没有办法清除它,这样就不会调用该函数两次?)

最佳答案

If I compare the tables side by side without the sum function, they come out exactly the same. However the total sum value is coming out different. Any idea what could be causing this?

这是因为将聚合与行级列值相结合。

您的查询将只有一行结果。

  • 第一个值表示获取的第一行列值的 getRankint 结果,
  • 第二个表示此类排名的总和 = count(*) * getRankit。这里的计数值是获取满足以下条件的行数where 条件。

关于mysql-为什么这两个查询返回不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23751489/

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