gpt4 book ai didi

sql-server - sql server 中列总和的算术溢出

转载 作者:行者123 更新时间:2023-12-02 01:56:26 25 4
gpt4 key购买 nike

我正在尝试获取列总数,但是当我运行此查询时,出现以下错误。有什么建议吗?

SELECT SUM(Size) as total
FROM AllDocs
Where DirName LIKE 'sites/test/test%'


ERROR:
Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type int.
Warning: Null value is eliminated by an aggregate or other SET operation.

最佳答案

虽然您的所有大小都可以放入 INT(最多 2^31 - 1),但它们的 SUM 却不能。

将它们转换为BIGINT:

SELECT  SUM(CAST(Size AS BIGINT)) as total
FROM AllDocs
WHERE DirName LIKE 'sites/test/test%'

关于sql-server - sql server 中列总和的算术溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1222877/

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