我有一个表,在一个双精度字段中有“NaN”。我只是想计算有多少项目是“NaN”:
Select count(*) from table
where col = 'NaN'
AnalysisException:DOUBLE 和 STRING 类型的操作数不可比较:col = 'NaN'
Select count(*) from table
where col is null
Result = 0(顺便说一句,此列中有大量 NaN 记录)
Select count(*) from table
where cast(col as string) = 'NaN'
结果 = 0
我如何在实际计算 NaN 行的地方执行此操作?
我会将 NaNs 转换为字符串,然后与
'nan'
进行比较
Select count(*) from table
where cast(col as string) = 'nan'
可以使用is_nan函数
select count(*) from table
where is_nan(col)
计算方式略有不同..
select sum(if(is_nan(column_name), 1, 0)) as nan_count, count(column_name) AS total_count
from table_name;