This example finds the average of the prices of all titles, substituting the value $10.00 for all NULL entries in the price column of the titles table.
USE pubs
GO
SELECT AVG(ISNULL(price, $10.00))
FROM titles
GO
Here is the result set:
--------------------------
14.24
(1 row(s) affected)
如果你想把空值变成0,用:
SELECT AVG(ISNULL(price, 0))
FROM titles
意思是把凡是Price的空值变成0之后求平均值。
感谢: lingbin(林斌) 的帮助,你的办法用于显示是没有问题的。
我现在遇到的主要问题是在计算中空值是不是计算的,比如:
select (a.Field1+b.Field2) As F1F2
from a,b
where a.ID=b.ID
如果工表中的Field1有空值,不管B表中的Field2是不是空,计算出来的F1F2一定是空的????在查询中加入Nz后是没有问题的,但是BCB不支持??