MySQL SUM在使用GROUP BY时不起作用 [英] MySQL SUM when using GROUP BY not working
本文介绍了MySQL SUM在使用GROUP BY时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
符号|大小
A | 12
B | 5
A | 3
A | 6
B | 8
我们希望看到如下图:
符号|大小
A | 21
B |
$ p> 从符号表中选择Symbol,sum(Size)按符号顺序按符号ASC
但是我们得到这个:
符号|大小
A | 12
B | 5
我做错了什么?!
Select 命令的某个地方发现了Un-SUMable表,而不是
左连接
有一个简单的连接
。虽然我仍然不明白为什么这会弄乱计算,我改变了这一点,现在它作品......对不起,我无法上传整件事...... Let's say we have this table:
Symbol | Size
A | 12
B | 5
A | 3
A | 6
B | 8
And we want a view like this:
Symbol | Size
A | 21
B | 13
So we use this:
Select Symbol, sum(Size) from table group by Symbol order by Symbol ASC
But instead we get this:
Symbol | Size
A | 12
B | 5
What am I doing wrong?!
解决方案
I found out that somewhere in the Select
commands that leaded to the Un-SUMable table instead of a left join
there was a simple join
.Although I still don't get why that should mess up the calculation, I changed that and now it works... I'm sorry I couldn't upload the whole thing...
这篇关于MySQL SUM在使用GROUP BY时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文