开发者

Counting a column in MySQL

Suppose that I have a column named '$开发者_如何学JAVA' 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!


SELECT SUM($) FROM your_table_name

I'm not sure $ is a valid column name though

UPDATE Tested in PHPMyAdmin and I was able to name a column $ and perform a SUM on it. Something new learned!


select sum($) from table_name;


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 column amount

SELECT SUM(amount) AS total FROM your_table;

Edit As mentioned by @Brendan you can have a column named $. I stand by my opinion that it would be confusing in code :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜