在 SQL 中没有得到正确的计数 [英] Not getting the correct count in SQL
本文介绍了在 SQL 中没有得到正确的计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对 SQL
完全陌生.我有一个与此类似的简单选择查询:
I am totally new to SQL
. I have a simple select query similar to this:
SELECT COUNT(col1) FROM table1
表中有大约 120 条记录并显示在 GUI
上.出于某种原因,此查询总是返回一个小于实际计数的数字.
There are some 120 records in the table and shown on the GUI
.
For some reason, this query always returns a number which is less than the actual count.
有人可以帮我吗?
推荐答案
您可能在 col1 列中有一些空值.聚合函数忽略空值.试试这个
You might have some null values in col1 column. Aggregate functions ignore nulls. try this
SELECT COUNT(ISNULL(col1,0)) FROM table1
这篇关于在 SQL 中没有得到正确的计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文