sql server中列和的算术溢出

MG.*_*MG. 20 sql-server

我试图得到一个列总数,但当我运行此查询时,我得到以下错误.有什么建议?

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.
Run Code Online (Sandbox Code Playgroud)

Qua*_*noi 37

虽然你的所有尺码都适合INT(最多2^31 - 1),但它们SUM不能.

将它们投入BIGINT:

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