总结一列中的bigint值

时间:2016-10-12 14:22:05

标签: mysql sum

我在mysql(v 5.6.23)中有一个表,描述如下:

mysql> select SUM(USAGE) as usage from as_dcm_testing;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'USAGE) as usage from as_dcm_testing' at line 1
mysql>

我想总结一下USAGE列中的所有值,所以我尝试使用sum函数。问题是我似乎遇到了错误。这个错误是因为用法是BIGINT而不是INT吗?如何总结具有bigint值的列中的值?

function getRes(needle , haystack){
    var nPos = haystack.search(needle);
    var sizeofNeedle = needle.length;

  return [haystack.substr(0 , nPos + sizeofNeedle) , haystack.substr(nPos + sizeofNeedle)];

}
  
var myResult = getRes("som" , "someText");

console.log(myResult);

提前致谢

A

1 个答案:

答案 0 :(得分:1)

USAGE是MySQL中的保留字。你必须把它包含在反引号中:

select SUM(`USAGE`) as `usage` from as_dcm_testing;