gpt4 book ai didi

mysql - 具有多个连接和求和函数的查询给出错误的总计或总和

转载 作者:可可西里 更新时间:2023-11-01 08:35:43 25 4
gpt4 key购买 nike

已发布的查询检索所有相关字段,但 SUM(af_py_commission) 函数导致问题,它只是在末尾和右侧添加一个额外的零结尾。

例如如果答案是 45,它将给出 450 并且该字段的数据格式是 float 否则这个查询工作完美......

我已经在同一字段上尝试了一个具有相同功能但没有连接的简单查询,因此它工作正常并给出正确的答案。谁能帮助我做错这件事>??

SELECT f.af_id AS af_if
, aff_cust_tbl.af_id AS cu_af_id
, aff_payment_tbl.af_cust_id AS pym_cus_id
, SUM(af_py_commission)
FROM aff_tbl AS f
INNER JOIN aff_tbl ON f.af_id = 2
INNER JOIN aff_cust_tbl ON aff_cust_tbl.af_id = 2
INNER JOIN aff_payment_tbl ON aff_payment_tbl.af_id = 2;

最佳答案

inner join有错误

试试这个:

SELECT
f.af_id AS af_if,
aff_cust_tbl.af_id AS cu_af_id,
aff_payment_tbl.af_cust_id AS pym_cus_id,
SUM(af_py_commission)
FROM aff_tbl AS f
INNER JOIN aff_tbl as f2
ON f.af_id = 2 AND f2.af_id=2
INNER JOIN aff_cust_tbl
ON aff_cust_tbl.af_id = 2
INNER JOIN aff_payment_tbl
ON aff_payment_tbl.af_id = 2;

编辑的行是

 INNER JOIN aff_tbl as f2
ON f.af_id = 2 AND f2.af_id=2

试试这个:

SELECT f.af_id                    AS af_if, 
aff_cust_tbl.af_id AS cu_af_id,
aff_payment_tbl.af_cust_id AS pym_cus_id,
Sum(af_py_commission)
FROM aff_tbl AS f
INNER JOIN aff_cust_tbl
ON f.af_id = aff_cust_tbl.af_id
INNER JOIN aff_payment_tbl
ON aff_payment_tbl.af_id = aff_cust_tbl.af_id
WHERE f.af_id = 2;

如果它没有给出正确的结果,请尝试不求和并在此处进行分析...

关于mysql - 具有多个连接和求和函数的查询给出错误的总计或总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12884035/

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