计算 MySQL 中的列数
假设我有一个名为“$”的列,其中有不同的值,例如:
id|| $
======
1 || 50
======
2 || 54
======
3 || 76
======
如何添加 $ 的值?一个查询会给我 50+54+76?真实的表大约有 20,000 行。
谢谢!
Suppose that I have a column named '$' and in it I have different values, for example:
id|| $
======
1 || 50
======
2 || 54
======
3 || 76
======
How can i add the values of $? A query that would give me 50+54+76? The real table has around 20,000 rows.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
SUM()
函数。由于我不相信您可以拥有名为$
的列(即使可以,似乎也会产生意想不到的后果),因此我将您的列命名为amount
编辑 正如@Brendan 所提到的,您可以有一个名为
$
的列。我坚持我的观点,这在代码中会令人困惑:)Use the
SUM()
function. Since I don't believe you can have a column named$
(and even if you can, it seems there would be unintended consequences), I've named your columnamount
Edit As mentioned by @Brendan you can have a column named
$
. I stand by my opinion that it would be confusing in code :)我不确定 $ 是有效的列名
尽管UPDATE
在 PHPMyAdmin 中进行测试,我能够命名一个列
$
并对其执行SUM
。学到了新东西!I'm not sure $ is a valid column name though
UPDATE
Tested in PHPMyAdmin and I was able to name a column
$
and perform aSUM
on it. Something new learned!