SQL 计数溢出

2021-12-30 00:00:00 sql overflow count sql-server

这是我的查询:

SELECT COUNT(*) FROM Similarities WHERE T1Similarity = 0 OR T2Similarity = 0

结果如下:

消息 8115,级别 16,状态 2,第 1 行

Msg 8115, Level 16, State 2, Line 1

将表达式转换为数据类型 int 时出现算术溢出错误.

Arithmetic overflow error converting expression to data type int.

该表有 40 亿行.我不希望这个查询很快,但大约 5 分钟后,它失败并出现溢出错误.对于比 int 更大的数据,是否有 COUNT 函数?

The table has 4 billion rows. I don't expect this query to be fast, but after about 5mins, it fails with an overflow error. Is there a COUNT function for bigger data than int?

谢谢.

推荐答案

使用 COUNT_BIG

SELECT COUNT_BIG(*) FROM Similarities WHERE T1Similarity = 0 OR T2Similarity = 0

相关文章