我正在尝试执行一个计算平均值、最小值、最大值和计数的基本查询。
SELECT
MIN(column) as min,
MAX(column) as max,
AVG(column) as avg,
count(*) as count
FROM database.dbo.table;
其中列的类型为int
,数据库是azure sql标准。
作为回报,我收到一个错误:“将表达式转换为数据类型 int 时出现算术溢出错误”
为什么 int 首先会出现转换为 int 的问题?我可以添加一些东西来使其适用于所有数字类型吗?
尝试使用计数大像这样:
SELECT
MIN(column) as min,
MAX(column) as max,
AVG(column) as avg,
count_big(*) as count
FROM database.dbo.table;
您还尝试将您的列转换为 BIGINT,如下所示:
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;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)