gpt4 book ai didi

mysql - 汇总列中的 bigint 值

转载 作者:行者123 更新时间:2023-11-28 23:24:19 25 4
gpt4 key购买 nike

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

mysql> describe as_dcm_testing;
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| LCID | varchar(32) | NO | PRI | NULL | |
| LASTACTIVITY | varchar(32) | YES | | NULL | |
| USAGE | bigint(20) | YES | | NULL | |
| SERVICELEVEL | varchar(16) | YES | | NULL | |
+--------------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

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

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是MySQL中的保留字。您必须将其括在反引号中:

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

关于mysql - 汇总列中的 bigint 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40001094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com