我在 MySQL 中使用 SUM() 时遇到问题
我想获取由特定参加者参加的特定客户的BalanceAmt。标准是顾客可以购买不止一件商品。每个购买的物品都被单独记录。在某些情况下,“参加者”值将为 NULL。
这是我的查询:
SELECT Customer, AttendedBy, SUM(BalanceAmt) FROM billing GROUP BY Customer
HAVING AttendedBy='attender' AND Customer='CustomerName'
我的问题是我得到了“出席者”未参与的值的总和(即,包括 NULL 值)。 帮我做一下..
提前谢谢..
I want to fetch the BalanceAmt of a particular Customer attended by a particular attender. The criteria is that a customer may buy more than one items. Each bought items has been recorded individually. At some cases 'attender' value would be NULL.
Here's my query:
SELECT Customer, AttendedBy, SUM(BalanceAmt) FROM billing GROUP BY Customer
HAVING AttendedBy='attender' AND Customer='CustomerName'
My problem is I'm getting the value summed up not attended by the 'attender' (i.e., including NULL value).
Help me to do it..
Thanx in advance..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我感觉问题没有得到正确的答案,但我会像这样编写 SELECT 语句,但
我不确定AssignedTo 是什么。如果您想要 Customer、AssignedTo 的总和,那么它将是:
I have the feeling haven't gotten the question right, but I would write the SELECT Statement like this
I am not sure what the AssignedTo is. If you want the sum on Customer, AssignedTo then it would be:
我认为您需要包含一个
where
子句来排除您的空值...类似以下内容应该可以解决问题:HTH。
I think you need to include a
where
clause to exclude your null values... Something like the following should do the trick:HTH.
在上面的查询中,不需要
group by
,因为您已将该列放在where
子句中。您可以从
select
中删除它,也可以删除group by
。您可以编写类似这样的内容,以获得按客户计算的总和。
In your above query
group by
is not required as you have put the column in thewhere
clause.You can remove it from
select
and you removegroup by
as well.You can write something like this, to get the Customer-wise sum.