gpt4 book ai didi

mysql - MySQL 中的这个 group by 查询有什么问题?

转载 作者:行者123 更新时间:2023-11-30 22:36:14 27 4
gpt4 key购买 nike

我的数据库结构:
enter image description here
每个“wp_custombill”都有多个“wp_customuser”

我想查询所有的custombill,每个custombill 都有其customuser 的总和。我的查询是

select cb.ID, cb.Description, cb.amount, SUM(cu.amount) 
from wp_customuser as cu
inner join wp_custombill as cb
on cu.email = cb.Email
group by cb.ID, cb.Description, cb.amount

但结果似乎是 sum(cu.Amount) 汇总了所有 CustomUser 的记录。 enter image description here

最佳答案

我猜你的 wp_custombill ids (1,2,3) 有相同的 email但是没有数据样本是很难测试的。

否则你的查询看起来没问题。

关于mysql - MySQL 中的这个 group by 查询有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32470572/

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