Mon*_*RPG 27 int sum overflow sql-server-2008-r2 arithmeticexception
我正在使用SQL Server 2008 R2并且我有一个INT列,其中插入的数据永远不会超过最大值INT,但我有一个查询,它使用的SUM函数在执行时超过最大INT限制并抛出标题中提到的错误.
我希望能够执行此查询而不将列类型更改INT为BIGINT.
这是我的查询:
SELECT UserId,
SUM( PokemonExp ) AS TotalExp,
MAX( PokemonLevel ) AS MaxPokeLevel
FROM mytable
GROUP BY UserId
ORDER BY TotalExp DESC
Run Code Online (Sandbox Code Playgroud)
注:该PokemonExp列的类型的INT.
Mic*_*aga 56
表达式类型SUM确定返回类型.
请尝试以下方法:
SELECT UserId,
SUM( CAST( PokemonExp AS BIGINT )) AS TotalExp,
MAX( PokemonLevel ) AS MaxPokeLevel
FROM mytable
GROUP BY UserId
ORDER BY TotalExp DESC
Run Code Online (Sandbox Code Playgroud)