算术溢出错误将表达式转换为基本统计信息的数据类型int [英] Arithmetic overflow error converting expression to data type int for basic statistics

查看:43
本文介绍了算术溢出错误将表达式转换为基本统计信息的数据类型int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一个基本查询,以计算平均值,最小值,最大值和计数.

I am trying to do a basic query that calculates average, min, max, and count.

SELECT
 MIN(column) as min,
 MAX(column) as max,
 AVG(column) as avg,
 count(*) as count
FROM database.dbo.table;

其中column的类型为 int ,并且数据库为Azure SQL标准.

Where column is of type int, and the database is azure sql standard.

作为回报,我得到一个错误:将表达式转换为数据类型int的算术溢出错误"

and in return, i get an error: "Arithmetic overflow error converting expression to data type int"

为什么int首先会遇到强制转换为int的问题?还有什么我可以补充的,可以使所有数字类型都能使用吗?

Why is int getting a casting-to-int problem in the first place? and is there something I can add that will make this work on all numerical types?

推荐答案

尝试使用 count_big 像这样:

SELECT
 MIN(column) as min,
 MAX(column) as max,
 AVG(column) as avg,
 count_big(*) as count
FROM database.dbo.table;

您还尝试像这样将列以BIGINT的形式投放:

Also you try to CAST your column as BIGINT like this:

 SELECT
 MIN(CAST(column as BIGINT)) as min,
 MAX(CAST(column as BIGINT)) as max,
 AVG(CAST(column as BIGINT)) as avg,
 count_big(*) as count
FROM database.dbo.table;

这篇关于算术溢出错误将表达式转换为基本统计信息的数据类型int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆